Class ScheduledTime

java.lang.Object
  extended by ScheduledTime

public class ScheduledTime
extends java.lang.Object

The ScheduledTime class is a simplified encapsulation of times. A ScheduledTime object has hours and minutes. Hours in the set {8,9,10,11} are considered AM and hours in the interval {12,1,2,3,4,5,6,7} are considered PM. Minutes must be the interval [0,59].

When operating on ScheduledTime objects, the minutes will be truncated. The 'truncation value' can be changed using the setTruncationValue() method. By default, the truncation value is set to 1, which has no impact on operations. When set to 5, for example, 8:01 will be truncated to 8:00 and 8:49 will be truncated to 8:45.

A ScheduledTime object is immutable. That is, once it is created, its attributes can't be changed. (However, the way in which ScheduledTime objects are operated on can be changed using the setTruncationValue() method.)


Constructor Summary
ScheduledTime(int hour, int minute)
           Explicit Value Constructor
ScheduledTime(java.lang.String hhmm)
           Explicit Value Constructor
 
Method Summary
 int compareTo(ScheduledTime other)
           Compare this ScheduledTime to the ScheduledTime named other.
 int getHour()
          Get the hour associated with this ScheduledTime
 int getMinute()
          Get the minute (truncated appropriately) associated with this ScheduledTime
static void setTruncationValue(int value)
          Set the truncation value to use for all ScheduledTime objects.
 java.lang.String toString()
          Returns a String representation of this ScheduledTime formatted as hh:mm (with the minute truncated appropriately)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScheduledTime

public ScheduledTime(int hour,
                     int minute)
              throws java.lang.IllegalArgumentException

Explicit Value Constructor

If the hour or minute is invalid, this constructor throws an IllegalArgumentException.

Parameters:
hour - The hour for this ScheduledTime
minute - The minute for this ScheduledTime
Throws:
java.lang.IllegalArgumentException

ScheduledTime

public ScheduledTime(java.lang.String hhmm)
              throws java.lang.IllegalArgumentException

Explicit Value Constructor

If the String representation is invalid, this constructor throws an IllegalArgumentException.

Parameters:
hhmm - A String representation (in hh:mm format)
Throws:
java.lang.IllegalArgumentException
Method Detail

compareTo

public int compareTo(ScheduledTime other)

Compare this ScheduledTime to the ScheduledTime named other. This method returns -1 if this is earlier than other, 0 if this is the same is other, and 1 if this is after other.

Note that this method truncates the minutes when performing the comparison. So, if the truncation value is 5, 8:00 and 8:04 are the same.


getHour

public int getHour()
Get the hour associated with this ScheduledTime

Returns:
The hour

getMinute

public int getMinute()
Get the minute (truncated appropriately) associated with this ScheduledTime

Returns:
The minute

setTruncationValue

public static void setTruncationValue(int value)
Set the truncation value to use for all ScheduledTime objects. For example, if the truncation value is set to 5, 8:01 will be 'rounded down'/truncated to 8:00 and 8:49 will be truncated to 8:45.

Parameters:
value - The truncation value to use

toString

public java.lang.String toString()
Returns a String representation of this ScheduledTime formatted as hh:mm (with the minute truncated appropriately)

Overrides:
toString in class java.lang.Object
Returns:
The String representation


James Madison University, Department of Computer Science