/** * Adds the specified milliseconds of days to this time and returns the * resulting time. The number of milliseconds may be negative, in which * case the result will be a time prior to this time. * * @param milliseconds * The number of milliseconds to add to this time. * * @return * The resulting time. */ public Time add(int milliseconds) { return new Time(toMilliseconds() + milliseconds); }
public boolean contains(Time time) { if (time == null) { throw new IllegalArgumentException("time is null."); } boolean contains; if (start.compareTo(end) < 0) { contains = (start.compareTo(time) <= 0 && end.compareTo(time) >= 0); } else { contains = (end.compareTo(time) <= 0 && start.compareTo(time) >= 0); } return contains; }
/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
public int getLength() { return Math.abs(start.subtract(end)) + 1; }
/** * Gets the number of milliseconds in between this time and the specified * time. If this time represents a time later than the specified time, the * difference will be positive. If this time represents a time before the * specified time, the difference will be negative. If the two times represent * the same time, the difference will be zero. * * @param time * The time to subtract from this time. * * @return * The number of milliseconds in between this time and <tt>time</tt>. */ public int subtract(Time time) { if (time == null) { throw new IllegalArgumentException(); } return toMilliseconds() - time.toMilliseconds(); }
/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
public int getLength() { return Math.abs(this.start.subtract(this.end)) + 1; }
/** * Gets the number of milliseconds in between this time and the specified * time. If this time represents a time later than the specified time, the * difference will be positive. If this time represents a time before the * specified time, the difference will be negative. If the two times represent * the same time, the difference will be zero. * * @param time * The time to subtract from this time. * * @return * The number of milliseconds in between this time and <tt>time</tt>. */ public int subtract(Time time) { if (time == null) { throw new IllegalArgumentException(); } return toMilliseconds() - time.toMilliseconds(); }
public boolean contains(Time time) { if (time == null) { throw new IllegalArgumentException("time is null."); } boolean contains; if (this.start.compareTo(this.end) < 0) { contains = (this.start.compareTo(time) <= 0 && this.end.compareTo(time) >= 0); } else { contains = (this.end.compareTo(time) <= 0 && this.start.compareTo(time) >= 0); } return contains; }
/** * Adds the specified milliseconds of days to this time and returns the * resulting time. The number of milliseconds may be negative, in which * case the result will be a time prior to this time. * * @param milliseconds * The number of milliseconds to add to this time. * * @return * The resulting time. */ public Time add(int milliseconds) { return new Time(toMilliseconds() + milliseconds); }
/** * Creates a new time representing the specified time string. The time * string must be in the full <tt>ISO 8601</tt> extended "time" format, * which is <tt>[hh]:[mm]:[ss]</tt>. An optional millisecond suffix of * the form <tt>.[nnn]</tt> is also supported. * * @param value * A string in the form of <tt>[hh]:[mm]:[ss]</tt> or * <tt>[hh]:[mm]:[ss].[nnn]</tt> (e.g. 17:19:20 or 17:19:20.412). */ public static Time decode(String value) { Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid time format: " + value); } int hour = Integer.parseInt(matcher.group(1)); int minute = Integer.parseInt(matcher.group(2)); int second = Integer.parseInt(matcher.group(3)); String millisecondSequence = matcher.group(4); int millisecond = (millisecondSequence == null) ? 0 : Integer.parseInt(millisecondSequence.substring(1)); return new Time(hour, minute, second, millisecond); } }
public boolean contains(Range range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Range normalizedRange = range.normalize(); boolean contains; if (this.start.compareTo(this.end) < 0) { contains = (this.start.compareTo(normalizedRange.start) <= 0 && this.end.compareTo(normalizedRange.end) >= 0); } else { contains = (this.end.compareTo(normalizedRange.start) <= 0 && this.start.compareTo(normalizedRange.end) >= 0); } return contains; }
public Range(Dictionary<String, ?> range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Object startRange = range.get(START_KEY); Object endRange = range.get(END_KEY); if (startRange == null) { throw new IllegalArgumentException(START_KEY + " is required."); } if (endRange == null) { throw new IllegalArgumentException(END_KEY + " is required."); } if (startRange instanceof String) { this.start = Time.decode((String)startRange); } else { this.start = (Time)startRange; } if (endRange instanceof String) { this.end = Time.decode((String)endRange); } else { this.end = (Time)endRange; } }
/** * Creates a new time representing the specified time string. The time * string must be in the full <tt>ISO 8601</tt> extended "time" format, * which is <tt>[hh]:[mm]:[ss]</tt>. An optional millisecond suffix of * the form <tt>.[nnn]</tt> is also supported. * * @param value * A string in the form of <tt>[hh]:[mm]:[ss]</tt> or * <tt>[hh]:[mm]:[ss].[nnn]</tt> (e.g. 17:19:20 or 17:19:20.412). */ public static Time decode(String value) { Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid time format: " + value); } int hour = Integer.parseInt(matcher.group(1)); int minute = Integer.parseInt(matcher.group(2)); int second = Integer.parseInt(matcher.group(3)); String millisecondSequence = matcher.group(4); int millisecond = (millisecondSequence == null) ? 0 : Integer.parseInt(millisecondSequence.substring(1)); return new Time(hour, minute, second, millisecond); } }
public boolean intersects(Range range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Range normalizedRange = range.normalize(); boolean intersects; if (this.start.compareTo(this.end) < 0) { intersects = (this.start.compareTo(normalizedRange.end) <= 0 && this.end.compareTo(normalizedRange.start) >= 0); } else { intersects = (this.end.compareTo(normalizedRange.end) <= 0 && this.start.compareTo(normalizedRange.start) >= 0); } return intersects; }
public Range(Dictionary<String, ?> range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Object start = range.get(START_KEY); Object end = range.get(END_KEY); if (start == null) { throw new IllegalArgumentException(START_KEY + " is required."); } if (end == null) { throw new IllegalArgumentException(END_KEY + " is required."); } if (start instanceof String) { this.start = Time.decode((String)start); } else { this.start = (Time)start; } if (end instanceof String) { this.end = Time.decode((String)end); } else { this.end = (Time)end; } }
public boolean contains(Range range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Range normalizedRange = range.normalize(); boolean contains; if (start.compareTo(end) < 0) { contains = (start.compareTo(normalizedRange.start) <= 0 && end.compareTo(normalizedRange.end) >= 0); } else { contains = (end.compareTo(normalizedRange.start) <= 0 && start.compareTo(normalizedRange.end) >= 0); } return contains; }
public static Range decode(String value) { if (value == null) { throw new IllegalArgumentException(); } Range range; if (value.startsWith("{")) { try { range = new Range(JSONSerializer.parseMap(value)); } catch (SerializationException exception) { throw new IllegalArgumentException(exception); } } else { range = new Range(Time.decode(value)); } return range; } }