net.degreedays.time
Class Time

java.lang.Object
  extended by net.degreedays.time.Time
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public final class Time
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

A simple hour-and-minute measure of time, ranging from 00:00 to 23:59 (inclusive).

Since:
1.2

Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.


Constructor Summary
Time(int hour, int minute)
          Constructs a Time object representing a time with the specified hour and minute.
 
Method Summary
 boolean after(Time comparisonTime)
          Returns true if this Time is chronologically after comparisonTime (assuming both are times within the same day); false otherwise.
 boolean before(Time comparisonTime)
          Returns true if this Time is chronologically before comparisonTime (assuming both are times within the same day); false otherwise.
 int compareTo(java.lang.Object comparisonTime)
          Compares two Time objects for chronological ordering (assuming both are times within the same day).
 boolean equals(java.lang.Object o)
          Returns true if o is a Time object with an equal hour() and minute().
static Time fromCalendar(java.util.Calendar calendar)
          Returns the non-null Time object represented by the HOUR_OF_DAY and MINUTE fields of calendar.
static Time fromString(java.lang.String timeString)
          Parses a string time in ISO hh:mm format (the format used by XML schema's time type) or hhmm format.
 int hashCode()
          Overridden to ensure consistency with equals.
 int hour()
          Returns a number between 0 and 23 (inclusive) representing the hour component of this Time.
 int minute()
          Returns a number between 0 and 59 (inclusive) representing the minute component of this Time.
static Time of(int hour, int minute)
          Returns a non-null Time object representing a time with the specified hour and minute.
 java.lang.String toNumericString()
          Returns a non-null, non-empty string representation of this Time in HHMM format.
 java.lang.String toString()
          Returns a non-null, non-empty string representation of this Time in hh:mm format.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Time

public Time(int hour,
            int minute)
Constructs a Time object representing a time with the specified hour and minute. It is usually better to call of(int, int) as that can re-use cached instances to conserve memory.

Parameters:
hour - the hour - a number between 0 and 23 (inclusive).
minute - the minute - a number between 0 and 59 (inclusive).
Throws:
java.lang.IllegalArgumentException - if either of the parameters are outside of their allowed ranges.
See Also:
of(int, int)
Method Detail

hour

public int hour()
Returns a number between 0 and 23 (inclusive) representing the hour component of this Time.


minute

public int minute()
Returns a number between 0 and 59 (inclusive) representing the minute component of this Time.


of

public static Time of(int hour,
                      int minute)
Returns a non-null Time object representing a time with the specified hour and minute. This will return Time objects from an internal cache when possible, to conserve memory.

Parameters:
hour - the hour - a number between 0 and 23 (inclusive).
minute - the minute - a number between 0 and 59 (inclusive).
Throws:
java.lang.IllegalArgumentException - if either of the parameters are outside of their allowed ranges.

fromString

public static Time fromString(java.lang.String timeString)
                       throws java.lang.NumberFormatException
Parses a string time in ISO hh:mm format (the format used by XML schema's time type) or hhmm format.

Returns:
a non-null Day object corresponding to the time represented by timeString.
Throws:
java.lang.NullPointerException - if timeString is null.
java.lang.NumberFormatException - if timeString has an invalid format.
See Also:
toString(), toNumericString()

fromCalendar

public static Time fromCalendar(java.util.Calendar calendar)
Returns the non-null Time object represented by the HOUR_OF_DAY and MINUTE fields of calendar.

Throws:
java.lang.NullPointerException - if calendar is null.

toNumericString

public java.lang.String toNumericString()
Returns a non-null, non-empty string representation of this Time in HHMM format.

See Also:
toString(), fromString(java.lang.String)

toString

public java.lang.String toString()
Returns a non-null, non-empty string representation of this Time in hh:mm format.

Overrides:
toString in class java.lang.Object
See Also:
toNumericString(), fromString(java.lang.String)

equals

public boolean equals(java.lang.Object o)
Returns true if o is a Time object with an equal hour() and minute().

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overridden to ensure consistency with equals.

Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(java.lang.Object comparisonTime)
Compares two Time objects for chronological ordering (assuming both are times within the same day).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
comparisonTime - the Time to be compared (the declared type is Object but it must be an object that can be cast to Time). Cannot be null.
Returns:
a negative integer if this Time is before comparisonTime; zero if this Time is equal to comparisonTime; or a positive integer if this Time is after comparisonTime.
Throws:
java.lang.NullPointerException - if comparisonTime is null.
java.lang.ClassCastException - if comparisonTime is not a Time object.
See Also:
before(net.degreedays.time.Time), after(net.degreedays.time.Time)

before

public boolean before(Time comparisonTime)
Returns true if this Time is chronologically before comparisonTime (assuming both are times within the same day); false otherwise.

Throws:
java.lang.NullPointerException - if comparisonTime is null.
See Also:
after(net.degreedays.time.Time), compareTo(java.lang.Object)

after

public boolean after(Time comparisonTime)
Returns true if this Time is chronologically after comparisonTime (assuming both are times within the same day); false otherwise.

Throws:
java.lang.NullPointerException - if comparisonTime is null.
See Also:
before(net.degreedays.time.Time), compareTo(java.lang.Object)


www.degreedays.net/api/