ソースを参照

Moved the HandlingEvent Comparator from DeliveryHistory to HandlingEvent

jorgen_falk 18 年 前
コミット
39def1ed33

+ 3
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java ファイルの表示

13
 
13
 
14
   private final Set<HandlingEvent> events;
14
   private final Set<HandlingEvent> events;
15
 
15
 
16
-  private static final HandlingEventByTimeComparator HANDLING_EVENT_COMPARATOR = new HandlingEventByTimeComparator();
16
+ 
17
 
17
 
18
   public DeliveryHistory() {
18
   public DeliveryHistory() {
19
     this(Collections.<HandlingEvent>emptySet());
19
     this(Collections.<HandlingEvent>emptySet());
37
    */
37
    */
38
   public List<HandlingEvent> eventsOrderedByTime() {
38
   public List<HandlingEvent> eventsOrderedByTime() {
39
     List<HandlingEvent> eventList = new ArrayList<HandlingEvent>(events);
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
     return Collections.unmodifiableList(eventList);
41
     return Collections.unmodifiableList(eventList);
42
   }
42
   }
43
 
43
 
58
     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
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 ファイルの表示

1
 package se.citerus.dddsample.domain;
1
 package se.citerus.dddsample.domain;
2
 
2
 
3
-import javax.persistence.*;
3
+import java.util.Comparator;
4
 import java.util.Date;
4
 import java.util.Date;
5
 import java.util.UUID;
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
  * HandlingEvent links the type of handling with a CarrierMovement.
15
  * HandlingEvent links the type of handling with a CarrierMovement.
9
  * 
16
  * 
14
  */
21
  */
15
 @Entity
22
 @Entity
16
 public class HandlingEvent {
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
   @Id
33
   @Id
19
   private String id;
34
   private String id;

+ 3
- 1
dddsample/src/main/java/se/citerus/dddsample/util/SampleDataGenerator.java ファイルの表示

42
         {UUID.randomUUID().toString().getBytes(), new Timestamp(100), new Timestamp(101), "UNLOAD", 2, "CAR_005", "XYZ"},        
42
         {UUID.randomUUID().toString().getBytes(), new Timestamp(100), new Timestamp(101), "UNLOAD", 2, "CAR_005", "XYZ"},        
43
         {UUID.randomUUID().toString().getBytes(), new Timestamp(110), new Timestamp(111), "CLAIM", 2, null, "XYZ"},
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
         {UUID.randomUUID().toString().getBytes(), new Timestamp(0), new Timestamp(1), "RECEIVE", 2, null, "ZYX"},  
46
         {UUID.randomUUID().toString().getBytes(), new Timestamp(0), new Timestamp(1), "RECEIVE", 2, null, "ZYX"},  
47
         {UUID.randomUUID().toString().getBytes(), new Timestamp(10), new Timestamp(11), "LOAD", 2, "CAR_007", "ZYX"},
47
         {UUID.randomUUID().toString().getBytes(), new Timestamp(10), new Timestamp(11), "LOAD", 2, "CAR_007", "ZYX"},
48
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "UNLOAD", 7, "CAR_007", "ZYX"},
48
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "UNLOAD", 7, "CAR_007", "ZYX"},
52
         
52
         
53
         //ABC
53
         //ABC
54
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "CLAIM", 2, null, "ABC"}
54
         {UUID.randomUUID().toString().getBytes(), new Timestamp(20), new Timestamp(21), "CLAIM", 2, null, "ABC"}
55
+        
56
+        //CBA
55
     };
57
     };
56
     for (Object[] handlingEventArg : handlingEventArgs) {
58
     for (Object[] handlingEventArg : handlingEventArgs) {
57
       jdbcTemplate.update(handlingEventSql, handlingEventArg);
59
       jdbcTemplate.update(handlingEventSql, handlingEventArg);

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/repository/HandlingEventRepositoryTest.java ファイルの表示

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