Make Timeslots comparable by start date
authorGeorgios Gousios <gousiosg@gmail.com>
Thu, 22 Dec 2011 15:56:42 +0000 (17:56 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Thu, 22 Dec 2011 15:59:07 +0000 (17:59 +0200)
src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/Timeslot.scala

index 8d050ff..074f3c6 100644 (file)
@@ -43,7 +43,7 @@ import scala.collection.mutable
  *
  * @author Georgios Gousios <gousiosg@gmail.com>
  */
-case class Timeslot(from: Date, to: Date) {
+case class Timeslot(from: Date, to: Date) extends Ordered[Timeslot] {
 
   /* Preconditions to ensure correct object creations */
   assert(from != null)
@@ -167,4 +167,13 @@ case class Timeslot(from: Date, to: Date) {
 
     start ++ build(List(), overlaps) ++ end
   }
+
+  /**
+   * Compares the starting times of two timeslots.
+   */
+  def compare(that: Timeslot): Int = {
+    if (this.startsBefore(that)) -1
+    else if (this.startsAfter(that)) 1
+    else 0
+  }
 }
\ No newline at end of file