浏览代码

Modified domain objects. Removed 'get' and 'set' prefix from getters&setters

jorgen_falk 18 年前
父节点
当前提交
ae22881faa

+ 5
- 5
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java 查看文件

@@ -36,7 +36,7 @@ public class Cargo {
36 36
     this.history = new DeliveryHistory();
37 37
   }
38 38
 
39
-  public DeliveryHistory getDeliveryHistory() {
39
+  public DeliveryHistory deliveryHistory() {
40 40
     return history;
41 41
   }
42 42
 
@@ -45,10 +45,10 @@ public class Cargo {
45 45
   }
46 46
 
47 47
   public boolean atFinalDestiation() {
48
-    return getCurrentLocation().equals(finalDestination);
48
+    return currentLocation().equals(finalDestination);
49 49
   }
50 50
 
51
-  public Location getCurrentLocation() {
51
+  public Location currentLocation() {
52 52
     HandlingEvent lastEvent = history.lastEvent();
53 53
     
54 54
     // If we have no last event, we have not even received the package. Return unknown location
@@ -56,13 +56,13 @@ public class Cargo {
56 56
       return Location.UNKNOWN;
57 57
     }
58 58
    
59
-    Location location = lastEvent.getLocation();
59
+    Location location = lastEvent.location();
60 60
     
61 61
     // If the last handling event has no idea of where the cargo is due to lack of CarrierMovement (like for CLAIM or RECEIVE events)
62 62
     // location must be calculated based on event type and origin or final destination
63 63
     // TODO: Maybe we need to refactor HandlingEvent.
64 64
     if (location == Location.UNKNOWN){
65
-      location = (lastEvent.getType() == HandlingEvent.Type.CLAIM) ? finalDestination : origin;
65
+      location = (lastEvent.type() == HandlingEvent.Type.CLAIM) ? finalDestination : origin;
66 66
     }
67 67
       
68 68
     return location;

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/CarrierId.java 查看文件

@@ -18,7 +18,7 @@ public class CarrierId implements Serializable {
18 18
     this.id = id;
19 19
   }
20 20
 
21
-  public String getId() {
21
+  public String id() {
22 22
     return id;
23 23
   }
24 24
 

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java 查看文件

@@ -54,7 +54,7 @@ public class DeliveryHistory {
54 54
 
55 55
   private static class HandlingEventByTimeComparator implements Comparator<HandlingEvent> {
56 56
     public int compare(HandlingEvent o1, HandlingEvent o2) {
57
-      return o1.getTimeOccurred().compareTo(o2.getTimeOccurred());
57
+      return o1.timeOccurred().compareTo(o2.timeOccurred());
58 58
     }
59 59
   }
60 60
 }

+ 10
- 10
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java 查看文件

@@ -63,26 +63,26 @@ public class HandlingEvent {
63 63
    */
64 64
   public boolean sameAs(HandlingEvent other) {
65 65
     return new EqualsBuilder().
66
-            append(this.getTimeOccurred(), other.getTimeOccurred()).
67
-            append(this.getLocation(), other.getLocation()).
68
-            append(this.getType(), other.getType()).
69
-            append(this.getCarrierMovement(), other.getCarrierMovement())
66
+            append(this.timeOccurred(), other.timeOccurred()).
67
+            append(this.location(), other.location()).
68
+            append(this.type(), other.type()).
69
+            append(this.carrierMovement(), other.carrierMovement())
70 70
             .isEquals();
71 71
   }
72 72
 
73
-  public Type getType() {
73
+  public Type type() {
74 74
     return type;
75 75
   }
76 76
 
77
-  public CarrierMovement getCarrierMovement() {
77
+  public CarrierMovement carrierMovement() {
78 78
     return carrierMovement;
79 79
   }
80 80
 
81
-  public Date getTimeOccurred() {
81
+  public Date timeOccurred() {
82 82
     return timeOccurred;
83 83
   }
84 84
 
85
-  public Date getTimeRegistered() {
85
+  public Date timeRegistered() {
86 86
     return timeRegistered;
87 87
   }
88 88
 
@@ -98,7 +98,7 @@ public class HandlingEvent {
98 98
    * 
99 99
    * @return The Location
100 100
    */
101
-  public Location getLocation() {
101
+  public Location location() {
102 102
     Location location = Location.UNKNOWN;
103 103
     
104 104
     //My gosh! A switch statement....
@@ -129,7 +129,7 @@ public class HandlingEvent {
129 129
     this.cargos.addAll(cargosToRegister);
130 130
   }
131 131
   
132
-  public Set<Cargo> getRegisterdCargos(){
132
+  public Set<Cargo> registerdCargos(){
133 133
     return cargos;
134 134
   }
135 135
 

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/TrackingId.java 查看文件

@@ -22,7 +22,7 @@ public class TrackingId implements Serializable {
22 22
     this.id = id;
23 23
   }
24 24
 
25
-  public String getId() {
25
+  public String id() {
26 26
     return id;
27 27
   }
28 28
 

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java 查看文件

@@ -29,11 +29,11 @@ public class CargoRepositoryInMem implements CargoRepository {
29 29
   }
30 30
 
31 31
   public Cargo find(TrackingId trackingId) {
32
-    if (trackingId.getId().equalsIgnoreCase("DAE")){
32
+    if (trackingId.id().equalsIgnoreCase("DAE")){
33 33
       throw new DataRetrievalFailureException("Network failure. Please try again");
34 34
     }
35 35
     
36
-    return cargoDb.get(trackingId.getId());
36
+    return cargoDb.get(trackingId.id());
37 37
   }
38 38
   
39 39
   public void save(Cargo cargo) {

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java 查看文件

@@ -111,7 +111,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
111 111
 
112 112
   public void save(HandlingEvent event) {
113 113
     // Mimmick saving to database
114
-    for (Cargo cargo : event.getRegisterdCargos()) {
114
+    for (Cargo cargo : event.registerdCargos()) {
115 115
       cargo.handle(event);
116 116
     }
117 117
   }
@@ -120,7 +120,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
120 120
   public Set<HandlingEvent> findByTrackingId(final TrackingId trackingId) {
121 121
     Set<HandlingEvent> events = new HashSet<HandlingEvent>();
122 122
     for (HandlingEvent event : eventDB.values()) {
123
-      for (Cargo cargo : event.getRegisterdCargos()) {
123
+      for (Cargo cargo : event.registerdCargos()) {
124 124
         if (cargo.trackingId().equals(trackingId)) {
125 125
           events.add(event);
126 126
           break;

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java 查看文件

@@ -19,21 +19,21 @@ public class CargoServiceImpl implements CargoService {
19 19
       return null;
20 20
     }
21 21
     final CargoWithHistoryDTO dto = new CargoWithHistoryDTO(
22
-            cargo.trackingId().getId(),
22
+            cargo.trackingId().id(),
23 23
             cargo.origin().unlocode(),
24 24
             cargo.finalDestination().unlocode(),
25
-            cargo.getCurrentLocation().unlocode()
25
+            cargo.currentLocation().unlocode()
26 26
     );
27
-    final List<HandlingEvent> events = cargo.getDeliveryHistory().eventsOrderedByTime();
27
+    final List<HandlingEvent> events = cargo.deliveryHistory().eventsOrderedByTime();
28 28
     for (HandlingEvent event : events) {
29
-      CarrierMovement cm = event.getCarrierMovement();
29
+      CarrierMovement cm = event.carrierMovement();
30 30
       String carrierIdString =
31
-              (cm == null) ? Location.UNKNOWN.unlocode() : cm.carrierId().getId();
31
+              (cm == null) ? Location.UNKNOWN.unlocode() : cm.carrierId().id();
32 32
       dto.addEvent(new HandlingEventDTO(
33
-              event.getLocation().unlocode(),
34
-              event.getType().toString(),
33
+              event.location().unlocode(),
34
+              event.type().toString(),
35 35
               carrierIdString,
36
-              event.getTimeOccurred()
36
+              event.timeOccurred()
37 37
       ));
38 38
     }
39 39
     return dto;

+ 5
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java 查看文件

@@ -14,31 +14,31 @@ public class CargoTest extends TestCase {
14 14
     Location origin = new Location("SESTO");
15 15
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, destination);
16 16
 
17
-    assertEquals(Location.UNKNOWN, cargo.getCurrentLocation());
17
+    assertEquals(Location.UNKNOWN, cargo.currentLocation());
18 18
   }
19 19
   
20 20
   public void testCurrentLocationReceived() throws Exception {
21 21
     Cargo cargo = populateCargoReceivedStockholm();
22 22
 
23
-    assertEquals(new Location("SESTO"), cargo.getCurrentLocation());
23
+    assertEquals(new Location("SESTO"), cargo.currentLocation());
24 24
   }
25 25
 
26 26
   public void testCurrentLocationClaimed() throws Exception {
27 27
     Cargo cargo = populateCargoClaimedMelbourne();
28 28
 
29
-    assertEquals(new Location("AUMEL"), cargo.getCurrentLocation());
29
+    assertEquals(new Location("AUMEL"), cargo.currentLocation());
30 30
   }
31 31
   
32 32
   public void testCurrentLocationUnloaded() throws Exception {
33 33
     Cargo cargo = populateCargoOffHongKong();
34 34
 
35
-    assertEquals(new Location("CNHGK"), cargo.getCurrentLocation());
35
+    assertEquals(new Location("CNHGK"), cargo.currentLocation());
36 36
   }
37 37
 
38 38
   public void testCurrentLocationloaded() throws Exception {
39 39
     Cargo cargo = populateCargoOnHamburg();
40 40
 
41
-    assertEquals(new Location("DEHAM"), cargo.getCurrentLocation());
41
+    assertEquals(new Location("DEHAM"), cargo.currentLocation());
42 42
   }
43 43
 
44 44
   public void testAtFinalLocation() throws Exception {

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java 查看文件

@@ -14,7 +14,7 @@ public class HandlingEventTest extends TestCase {
14 14
     
15 15
     HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.LOAD, cm);
16 16
     
17
-    assertEquals(locationAAA, ev.getLocation());
17
+    assertEquals(locationAAA, ev.location());
18 18
   }
19 19
   
20 20
   public void testCurrentLocationUnloadEvent() throws Exception {
@@ -25,18 +25,18 @@ public class HandlingEventTest extends TestCase {
25 25
     
26 26
     HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.UNLOAD, cm);
27 27
     
28
-    assertEquals(locationBBB, ev.getLocation());
28
+    assertEquals(locationBBB, ev.location());
29 29
   }
30 30
   
31 31
   public void testCurrentLocationReceivedEvent() throws Exception {
32 32
     HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.RECEIVE, null);
33 33
 
34
-    assertEquals(Location.UNKNOWN, ev.getLocation());
34
+    assertEquals(Location.UNKNOWN, ev.location());
35 35
   }
36 36
   public void testCurrentLocationClaimedEvent() throws Exception {
37 37
     HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.CLAIM, null);
38 38
 
39
-    assertEquals(Location.UNKNOWN, ev.getLocation());
39
+    assertEquals(Location.UNKNOWN, ev.location());
40 40
   }
41 41
   
42 42
   public void testParseType() throws Exception {

+ 3
- 3
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java 查看文件

@@ -14,16 +14,16 @@ public class TrackingScenarioTest extends TestCase {
14 14
 
15 15
     Cargo cargo = populateCargo();
16 16
 
17
-    DeliveryHistory deliveryHistory = cargo.getDeliveryHistory();
17
+    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
18 18
 
19 19
     List<HandlingEvent> handlingEvents = deliveryHistory.eventsOrderedByTime();
20 20
 
21 21
     assertEquals(4, handlingEvents.size());
22 22
     final HandlingEvent event = deliveryHistory.lastEvent();
23 23
 
24
-    assertSame(HandlingEvent.Type.UNLOAD, event.getType());
24
+    assertSame(HandlingEvent.Type.UNLOAD, event.type());
25 25
     assertFalse(cargo.atFinalDestiation());
26
-    assertEquals("CNHKG", cargo.getCurrentLocation().unlocode());
26
+    assertEquals("CNHKG", cargo.currentLocation().unlocode());
27 27
 
28 28
   }
29 29
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/repository/CargoRepositoryTest.java 查看文件

@@ -39,7 +39,7 @@ public class CargoRepositoryTest extends AbstractTransactionalDataSourceSpringCo
39 39
     assertEquals(trackingId, cargo.trackingId());
40 40
     assertEquals(origin, cargo.origin());
41 41
     assertEquals(finalDestination, cargo.finalDestination());
42
-    assertEquals(Location.UNKNOWN, cargo.getCurrentLocation());
42
+    assertEquals(Location.UNKNOWN, cargo.currentLocation());
43 43
   }
44 44
 
45 45
 }

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java 查看文件

@@ -68,7 +68,7 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
68 68
       public Cargo answerWithinTransaction() throws Throwable {
69 69
         Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIG"), new Location("DEST"));
70 70
         CarrierMovement cm = new CarrierMovement(new CarrierId("CAR_001"), new Location("FROM"), new Location("TO"));
71
-        cargo.getDeliveryHistory().addEvent(
71
+        cargo.deliveryHistory().addEvent(
72 72
                 new HandlingEvent(new Date(10L), new Date(20L), HandlingEvent.Type.CLAIM, cm)
73 73
         );
74 74
         return cargo;

+ 6
- 6
dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java 查看文件

@@ -45,20 +45,20 @@ public class CargoTrackingControllerTest extends TestCase {
45 45
       public CargoWithHistoryDTO find(String trackingId) {
46 46
         Cargo cargo = new Cargo(new TrackingId(trackingId), new Location("AAA"), new Location("BBB"));
47 47
         HandlingEvent event = new HandlingEvent(new Date(10L), new Date(20L), HandlingEvent.Type.RECEIVE);
48
-        cargo.getDeliveryHistory().addEvent(event);
48
+        cargo.deliveryHistory().addEvent(event);
49 49
 
50 50
         // TODO: use DTO assemblers
51 51
         CargoWithHistoryDTO cargoDTO = new CargoWithHistoryDTO(
52
-                cargo.trackingId().getId(),
52
+                cargo.trackingId().id(),
53 53
                 cargo.origin().unlocode(),
54 54
                 cargo.finalDestination().unlocode(),
55
-                cargo.getCurrentLocation().unlocode()
55
+                cargo.currentLocation().unlocode()
56 56
         );
57 57
         cargoDTO.addEvent(new HandlingEventDTO(
58
-          event.getLocation().unlocode(),
59
-          event.getType().toString(),
58
+          event.location().unlocode(),
59
+          event.type().toString(),
60 60
           null, // TODO: event hierarchy will remove this kind of code
61
-          event.getTimeOccurred()));
61
+          event.timeOccurred()));
62 62
         return cargoDTO;
63 63
       }
64 64
     };