scheduler.db
Class Time

java.lang.Object
  extended by scheduler.db.Time
All Implemented Interfaces:
java.lang.Comparable<Time>

public class Time
extends java.lang.Object
implements java.lang.Comparable<Time>

A time object consisting of a minute and an hour.

Author:
Jan Lorenz Soliman

Nested Class Summary
 class Time.InvalidInputException
          Invalid input exception thrown in the set methods.
 
Field Summary
protected  int hour
          Integer representing hour
protected  int minute
          Integer representing minute
 
Constructor Summary
Time(int hour, int minute)
          A constructor for the Time object
 
Method Summary
 void addHalf()
          Adds a half-hour to a given time.
 int compareTo(Time t)
          For comparing times
 boolean equals(java.lang.Object t)
          Tests if the time is equal
 int getHour()
          Returns the hour
 int getMinute()
          Gets the minutes in a specific time
 int hashCode()
          Needed for hashes of times.
static boolean isWithin(Time start1, Time end1, Time start2, Time end2)
          Checks if a time interval is fits into another.
 boolean setHour(int hour)
          Sets the hour field
 boolean setMinute(int minute)
          Sets the minutes field
 java.lang.String standardString()
           
 java.lang.String toString()
          return the time in this format "HH:MM"
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

hour

protected int hour
Integer representing hour


minute

protected int minute
Integer representing minute

Constructor Detail

Time

public Time(int hour,
            int minute)
A constructor for the Time object

Method Detail

getHour

public int getHour()
Returns the hour


getMinute

public int getMinute()
Gets the minutes in a specific time
  pre:

  post:
         //
         // The minute field is an integer greater than 0
         // and less than 60
         //
         (minute >= 0 && minute < 60)
  

Returns:
The minute integer to set.

setMinute

public boolean setMinute(int minute)
Sets the minutes field
  pre:   //
         // The minute field is an integer greater than 0
         // and less than 60
         //
         (minute >= 0 && minute < 60)

  post:
         //
         // The minute field is equal to the parameter 
         //
         (this.minute == minute)
  

Parameters:
minute - The minute integer to set.
Returns:
true if the value was set, false otherwise.

setHour

public boolean setHour(int hour)
Sets the hour field
  pre:   //
         // The minute field is an integer greater than 0
         // and less than 60
         //
         (hour >= 0 && hour < 24)
  post:
         //
         // The hour field is equal to the parameter 
         //
         (this.hour == hour)
  

Parameters:
hour - The hour integer to set.
Returns:
true if the value was set, false otherwise.

equals

public boolean equals(java.lang.Object t)
Tests if the time is equal

Overrides:
equals in class java.lang.Object
Parameters:
t - A time object to compare to.

hashCode

public int hashCode()
Needed for hashes of times. Written by: Eric Liebowitz

Overrides:
hashCode in class java.lang.Object
Returns:
the sum of the hour and min

compareTo

public int compareTo(Time t)
For comparing times

Specified by:
compareTo in interface java.lang.Comparable<Time>
Parameters:
t - The compare to compare to this

isWithin

public static boolean isWithin(Time start1,
                               Time end1,
                               Time start2,
                               Time end2)
Checks if a time interval is fits into another.

Parameters:
start1 - start of the would be sub-interval
end1 - end of the would be sub-interval
start2 - start of the interval
end2 - end of the interval
Returns:
true if [start1,end1] is within [start2,end2]

toString

public java.lang.String toString()
return the time in this format "HH:MM"

Overrides:
toString in class java.lang.Object
Returns:
return the time in string format

standardString

public java.lang.String standardString()

addHalf

public void addHalf()
Adds a half-hour to a given time. Does not wrap around after 23:30.