Parcourir la source

Moved the HandlingEvent Comparator from DeliveryHistory to HandlingEvent

jorgen_falk il y a 18 ans
Parent
révision
39def1ed33

+ 3
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java Voir le fichier

@@ -13,7 +13,7 @@ public class DeliveryHistory {
13 13
 
14 14
   private final Set<HandlingEvent> events;
15 15
 
16
-  private static final HandlingEventByTimeComparator HANDLING_EVENT_COMPARATOR = new HandlingEventByTimeComparator();
16
+ 
17 17
 
18 18
   public DeliveryHistory() {
19 19
     this(Collections.<HandlingEvent>emptySet());
@@ -37,7 +37,7 @@ public class DeliveryHistory {
37 37
    */
38 38
   public List<HandlingEvent> eventsOrderedByTime() {
39 39
     List<HandlingEvent> eventList = new ArrayList<HandlingEvent>(events);
40
-    Collections.sort(eventList, HANDLING_EVENT_COMPARATOR);
40
+    Collections.sort(eventList, HandlingEvent.BY_COMPLETION_TIME_COMPARATOR);
41 41
     return Collections.unmodifiableList(eventList);
42 42
   }
43 43
 
@@ -58,9 +58,5 @@ public class DeliveryHistory {
58 58
     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
59 59
   }
60 60
 
61
-  private static class HandlingEventByTimeComparator implements Comparator<HandlingEvent> {
62
-    public int compare(HandlingEvent o1, HandlingEvent o2) {
63
-      return o1.completionTime().compareTo(o2.completionTime());
64
-    }
65
-  }
61
+
66 62
 }

+ 16
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java Voir le fichier

@@ -1,9 +1,16 @@
1 1
 package se.citerus.dddsample.domain;
2 2
 
3
-import javax.persistence.*;
3
+import java.util.Comparator;
4 4
 import java.util.Date;
5 5
 import java.util.UUID;
6 6
 
7
+import javax.persistence.Entity;
8
+import javax.persistence.EnumType;
9
+import javax.persistence.Enumerated;
10
+import javax.persistence.Id;
11
+import javax.persistence.JoinColumn;
12
+import javax.persistence.ManyToOne;
13
+
7 14
 /**
8 15
  * HandlingEvent links the type of handling with a CarrierMovement.
9 16
  * 
@@ -14,6 +21,14 @@ import java.util.UUID;
14 21
  */
15 22
 @Entity
16 23
 public class HandlingEvent {
24
+  /**
25
+   * Comparator used to be able to sort HandlingEvents according to their completion time
26
+   */
27
+  public static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR = new Comparator<HandlingEvent>(){
28
+    public int compare(HandlingEvent o1, HandlingEvent o2) {
29
+      return o1.completionTime().compareTo(o2.completionTime());
30
+    }
31
+  };
17 32
 
18 33
   @Id
19 34
   private String id;

+ 3
- 1
dddsample/src/main/java/se/citerus/dddsample/util/SampleDataGenerator.java Voir le fichier

@@ -42,7 +42,7 @@ public class SampleDataGenerator implements ServletContextListener {
42 42
         {UUID.randomUUID().toString().getBytes(), new Timestamp(100), new Timestamp(101), "UNLOAD", 2, "CAR_005", "XYZ"},        
43 43
         {UUID.randomUUID().toString().getBytes(), new Timestamp(110), new Timestamp(111), "CLAIM", 2, null, "XYZ"},
44 44
             
45
-        //ZYX (AUMEL - USCHI - DEHAM - SESTO)
45
+        //ZYX (AUMEL - USCHI - DEHAM -)
46 46
         {UUID.randomUUID().toString().getBytes(), new Timestamp(0), new Timestamp(1), "RECEIVE", 2, null, "ZYX"},  
47 47
         {UUID.randomUUID().toString().getBytes(), new Timestamp(10), new Timestamp(11), "LOAD", 2, "CAR_007", "ZYX"},
48 48
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "UNLOAD", 7, "CAR_007", "ZYX"},
@@ -52,6 +52,8 @@ public class SampleDataGenerator implements ServletContextListener {
52 52
         
53 53
         //ABC
54 54
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "CLAIM", 2, null, "ABC"}
55
+        
56
+        //CBA
55 57
     };
56 58
     for (Object[] handlingEventArg : handlingEventArgs) {
57 59
       jdbcTemplate.update(handlingEventSql, handlingEventArg);

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/repository/HandlingEventRepositoryTest.java Voir le fichier

@@ -44,10 +44,10 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
44 44
     DeliveryHistory dh = handlingEventRepository.findDeliveryHistory(new TrackingId("XYZ"));
45 45
 
46 46
     assertNotNull(dh);
47
-    assertEquals(1, dh.eventsOrderedByTime().size());
47
+    assertEquals(12, dh.eventsOrderedByTime().size());
48 48
     HandlingEvent lastEvent = dh.lastEvent();
49 49
     assertNotNull(lastEvent);
50
-    assertEquals("SESTO", lastEvent.location().unlocode());
50
+    assertEquals("AUMEL", lastEvent.location().unlocode());
51 51
     // TODO: the rest of the properties, and maybe a longer list of events
52 52
   }
53 53
 }