(no commit message)
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / Time.java
index 6679223bf3af77d14d3d462ca6f9a0e9e61bac88..16cae4f08d176ef3628dbf20299b9a65c7757825 100644 (file)
@@ -20,29 +20,32 @@ import java.text.DecimalFormat;
 import java.text.NumberFormat;
 
 /**
- * TIme at which a program starts or ends. 
+ * TIme at which a program starts or ends.
  */
-public class Time {
+public class Time implements Comparable {
 
     /**
-     * Number of seconds per minute. 
+     * Number of seconds per minute.
      */
     private static final double SECONDS_PER_MINUTE = 60.0;
 
     /**
-     * Hour of the time. 
+     * Hour of the time.
      */
     private int _hour;
 
     /**
-     * Minute of the hour. 
+     * Minute of the hour.
      */
     private int _minute;
 
     /**
-     * Constructs the time. 
-     * @param aHour Hour. 
-     * @param aMinute Minute. 
+     * Constructs the time.
+     * 
+     * @param aHour
+     *            Hour.
+     * @param aMinute
+     *            Minute.
      */
     public Time(int aHour, int aMinute) {
         _hour = aHour;
@@ -50,8 +53,9 @@ public class Time {
     }
 
     /**
-     * Gets the hour. 
-     * @return Hour. 
+     * Gets the hour.
+     * 
+     * @return Hour.
      */
     public int getHour() {
         return _hour;
@@ -59,7 +63,8 @@ public class Time {
 
     /**
      * Gets te minute.
-     * @return Minute. 
+     * 
+     * @return Minute.
      */
     public int getMinute() {
         return _minute;
@@ -77,10 +82,43 @@ public class Time {
     }
 
     /**
-     * Convert time to floating point value. Useful for comparing two times. 
-     * @return Converted value. 
+     * Convert time to floating point value. Useful for comparing two times.
+     * 
+     * @return Converted value.
      */
     float asFloat() {
         return (float) _hour + (float) _minute / (float) SECONDS_PER_MINUTE;
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if ( !(obj instanceof Time )) { 
+            return false; 
+        }
+        return toString().equals(obj.toString());
+    }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Comparable#compareTo(T)
+     */
+    public int compareTo(Object o) {
+        if ( !(o instanceof Time)) { 
+            throw new RuntimeException("object not an instance of Time"); 
+        }
+        Time time = (Time)o; 
+        return new Float(asFloat()).compareTo(new Float(time.asFloat()));
+    }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
 }