(no commit message)
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / guide / Time.java
index de1065cf2f3ed024a68734b51fa6267a6b1d6f03..2d05bac10928569be7063501337c2ff354af5c22 100644 (file)
@@ -24,6 +24,16 @@ import java.text.NumberFormat;
  */
 public class Time implements Comparable {
 
+    /**
+     * 
+     */
+    private static final int HOURS_PER_DAY = 24;
+
+    /**
+     * 
+     */
+    private static final int EARLY_HOUR = 3;
+
     /**
      * Number of seconds per minute.
      */
@@ -87,7 +97,13 @@ public class Time implements Comparable {
      * @return Converted value.
      */
     float asFloat() {
-        return (float) _hour + (float) _minute / (float) SECONDS_PER_MINUTE;
+        int hour = _hour;
+        // Hack to make sure that programs appearing shortly after midnight are sorted
+        // after those running during the day. 
+        if ( hour <= EARLY_HOUR ) { 
+            hour += HOURS_PER_DAY; 
+        }
+        return (float) hour + (float) _minute / (float) SECONDS_PER_MINUTE;
     }
 
     /*
@@ -96,25 +112,29 @@ public class Time implements Comparable {
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
-    public boolean equals(Object obj) {
-        if ( !(obj instanceof Time )) { 
-            return false; 
+    public boolean equals(Object aObject) {
+        if (!(aObject instanceof Time)) {
+            return false;
         }
-        return toString().equals(obj.toString());
+        return toString().equals(aObject.toString());
     }
-    
-    /* (non-Javadoc)
-     * @see java.lang.Comparable#compareTo(T)
+
+    /**
+     * Compares based on time. 
+     * @param aObject Time object to compare to. 
+     * @return See {@link Comparable#compareTo(T)}.
      */
-    public int compareTo(Object o) {
-        if ( !(o instanceof Time)) { 
-            throw new RuntimeException("object not an instance of Time"); 
+    public int compareTo(Object aObject) {
+        if (!(aObject instanceof Time)) {
+            throw new IllegalArgumentException("object not an instance of Time");
         }
-        Time time = (Time)o; 
+        Time time = (Time) aObject;
         return new Float(asFloat()).compareTo(new Float(time.asFloat()));
     }
-    
-    /* (non-Javadoc)
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see java.lang.Object#hashCode()
      */
     @Override