瀏覽代碼

Entity interface now has sameAs instead of sameIdentityAs, which expresses the intent more clearly.

peter_backlund 17 年之前
父節點
當前提交
5a8fcee732

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

@@ -178,14 +178,14 @@ public class Cargo implements Entity<Cargo> {
178 178
   }
179 179
 
180 180
   @Override
181
-  public boolean sameIdentityAs(final Cargo other) {
181
+  public boolean sameAs(final Cargo other) {
182 182
     return other != null && trackingId().sameValueAs(other.trackingId());
183 183
   }
184 184
 
185 185
   /**
186 186
    * @param object to compare
187 187
    * @return True if they have the same identity
188
-   * @see #sameIdentityAs(Cargo)
188
+   * @see #sameAs(Cargo)
189 189
    */
190 190
   @Override
191 191
   public boolean equals(final Object object) {
@@ -193,7 +193,7 @@ public class Cargo implements Entity<Cargo> {
193 193
     if (object == null || getClass() != object.getClass()) return false;
194 194
 
195 195
     final Cargo other = (Cargo) object;
196
-    return sameIdentityAs(other);
196
+    return sameAs(other);
197 197
   }
198 198
 
199 199
   /**
@@ -216,5 +216,5 @@ public class Cargo implements Entity<Cargo> {
216 216
   // Auto-generated surrogate key
217 217
   @SuppressWarnings("UnusedDeclaration")
218 218
   private Long id;
219
-  
219
+
220 220
 }

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Delivery.java 查看文件

@@ -96,7 +96,7 @@ public class Delivery implements ValueObject<Delivery> {
96 96
     }
97 97
 
98 98
     if (mostRecentHandlingActivity.type().sameValueAs(HandlingEvent.Type.CUSTOMS)) {
99
-      return !routeSpecification.destination().sameIdentityAs(mostRecentHandlingActivity.location());
99
+      return !routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
100 100
     } else {
101 101
       return !itinerary.isExpected(mostRecentHandlingActivity);
102 102
     }
@@ -109,7 +109,7 @@ public class Delivery implements ValueObject<Delivery> {
109 109
   boolean isUnloadedAtDestination(final RouteSpecification routeSpecification) {
110 110
     return mostRecentHandlingActivity != null &&
111 111
           (CLAIM.sameValueAs(mostRecentHandlingActivity.type()) || UNLOAD.sameValueAs(mostRecentHandlingActivity.type()) &&
112
-           routeSpecification.destination().sameIdentityAs(mostRecentHandlingActivity.location()));
112
+           routeSpecification.destination().sameAs(mostRecentHandlingActivity.location()));
113 113
   }
114 114
 
115 115
   /**

+ 7
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Itinerary.java 查看文件

@@ -65,8 +65,8 @@ public class Itinerary implements ValueObject<Itinerary> {
65 65
     if (handlingActivity.type() == HandlingEvent.Type.LOAD) {
66 66
       //Check that the there is a leg with same load location and voyage
67 67
       for (Leg leg : legs) {
68
-        if (leg.loadLocation().sameIdentityAs(handlingActivity.location()) &&
69
-          leg.voyage().sameIdentityAs(handlingActivity.voyage()))
68
+        if (leg.loadLocation().sameAs(handlingActivity.location()) &&
69
+          leg.voyage().sameAs(handlingActivity.voyage()))
70 70
           return true;
71 71
       }
72 72
       return false;
@@ -75,8 +75,8 @@ public class Itinerary implements ValueObject<Itinerary> {
75 75
     if (handlingActivity.type() == HandlingEvent.Type.UNLOAD) {
76 76
       //Check that the there is a leg with same unload location and voyage
77 77
       for (Leg leg : legs) {
78
-        if (leg.unloadLocation().sameIdentityAs(handlingActivity.location()) &&
79
-          leg.voyage().sameIdentityAs(handlingActivity.voyage()))
78
+        if (leg.unloadLocation().sameAs(handlingActivity.location()) &&
79
+          leg.voyage().sameAs(handlingActivity.voyage()))
80 80
           return true;
81 81
       }
82 82
       return false;
@@ -155,7 +155,7 @@ public class Itinerary implements ValueObject<Itinerary> {
155 155
 
156 156
     Leg lastAdded = null;
157 157
     for (Leg leg : this.legs) {
158
-      if (leg.voyage().sameIdentityAs(rescheduledVoyage)) {
158
+      if (leg.voyage().sameAs(rescheduledVoyage)) {
159 159
         Leg modifiedLeg = leg.withRescheduledVoyage(rescheduledVoyage);
160 160
         // This truncates the itinerary if the voyage rescheduling makes
161 161
         // it impossible to maintain the old unload-load chain.
@@ -190,7 +190,7 @@ public class Itinerary implements ValueObject<Itinerary> {
190 190
    */
191 191
   public Date loadTimeAt(final Location location) {
192 192
     for (Leg leg : legs) {
193
-      if (leg.loadLocation().sameIdentityAs(location)) {
193
+      if (leg.loadLocation().sameAs(location)) {
194 194
         return leg.loadTime();
195 195
       }
196 196
     }
@@ -203,7 +203,7 @@ public class Itinerary implements ValueObject<Itinerary> {
203 203
    */
204 204
   public Date unloadTimeAt(final Location location) {
205 205
     for (Leg leg : legs) {
206
-      if (leg.unloadLocation().sameIdentityAs(location)) {
206
+      if (leg.unloadLocation().sameAs(location)) {
207 207
         return leg.unloadTime();
208 208
       }
209 209
     }

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

@@ -27,7 +27,7 @@ public class Leg implements ValueObject<Leg> {
27 27
     Validate.notNull(unloadLocation, "Unload location is required");
28 28
     Validate.notNull(loadTime, "Load time is required");
29 29
     Validate.notNull(unloadTime, "Unload time is required");
30
-    Validate.isTrue(!loadLocation.sameIdentityAs(unloadLocation));
30
+    Validate.isTrue(!loadLocation.sameAs(unloadLocation));
31 31
     // TODO use a minimum time between unloading and loading?
32 32
     //Validate.isTrue(unloadTime.after(loadTime));
33 33
 

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Projections.java 查看文件

@@ -75,7 +75,7 @@ class Projections implements ValueObject<Projections> {
75 75
     final Location lastKnownLocation = delivery.lastKnownLocation();
76 76
     switch (delivery.transportStatus()) {
77 77
       case IN_PORT:
78
-        if (itinerary.firstLeg().loadLocation().sameIdentityAs(lastKnownLocation)) {
78
+        if (itinerary.firstLeg().loadLocation().sameAs(lastKnownLocation)) {
79 79
           return loadInFirstLocation(itinerary);
80 80
         } else {
81 81
           return loadOrClaimInNextLocation(itinerary, lastKnownLocation);
@@ -106,7 +106,7 @@ class Projections implements ValueObject<Projections> {
106 106
   private HandlingActivity loadOrClaimInNextLocation(final Itinerary itinerary, final Location activityLocation) {
107 107
     for (final Iterator<Leg> it = itinerary.legs().iterator(); it.hasNext();) {
108 108
       final Leg leg = it.next();
109
-      if (leg.unloadLocation().sameIdentityAs(activityLocation)) {
109
+      if (leg.unloadLocation().sameAs(activityLocation)) {
110 110
         if (it.hasNext()) {
111 111
           final Leg nextLeg = it.next();
112 112
 
@@ -126,7 +126,7 @@ class Projections implements ValueObject<Projections> {
126 126
 
127 127
   private HandlingActivity unloadInNextLocation(final Itinerary itinerary, final Location activityLocation) {
128 128
     for (final Leg leg : itinerary.legs()) {
129
-      if (leg.loadLocation().sameIdentityAs(activityLocation)) {
129
+      if (leg.loadLocation().sameAs(activityLocation)) {
130 130
         return new HandlingActivity(UNLOAD, leg.unloadLocation(), leg.voyage());
131 131
       }
132 132
     }

+ 3
- 6
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/RouteSpecification.java 查看文件

@@ -4,13 +4,10 @@ import org.apache.commons.lang.Validate;
4 4
 import org.apache.commons.lang.builder.EqualsBuilder;
5 5
 import org.apache.commons.lang.builder.HashCodeBuilder;
6 6
 import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.location.SampleLocations;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9 7
 import se.citerus.dddsample.domain.shared.AbstractSpecification;
10 8
 import se.citerus.dddsample.domain.shared.ValueObject;
11 9
 
12 10
 import java.util.Date;
13
-import java.lang.reflect.Field;
14 11
 
15 12
 /**
16 13
  * Route specification. Describes where a cargo orign and destination is,
@@ -31,7 +28,7 @@ public class RouteSpecification extends AbstractSpecification<Itinerary> impleme
31 28
     Validate.notNull(origin, "Origin is required");
32 29
     Validate.notNull(destination, "Destination is required");
33 30
     Validate.notNull(arrivalDeadline, "Arrival deadline is required");
34
-    Validate.isTrue(!origin.sameIdentityAs(destination), "Origin and destination can't be the same: " + origin);
31
+    Validate.isTrue(!origin.sameAs(destination), "Origin and destination can't be the same: " + origin);
35 32
 
36 33
     this.origin = origin;
37 34
     this.destination = destination;
@@ -86,8 +83,8 @@ public class RouteSpecification extends AbstractSpecification<Itinerary> impleme
86 83
   @Override
87 84
   public boolean isSatisfiedBy(final Itinerary itinerary) {
88 85
     return itinerary != null &&
89
-      origin().sameIdentityAs(itinerary.initialLoadLocation()) &&
90
-      destination().sameIdentityAs(itinerary.finalUnloadLocation()) &&
86
+      origin().sameAs(itinerary.initialLoadLocation()) &&
87
+      destination().sameAs(itinerary.finalUnloadLocation()) &&
91 88
       arrivalDeadline().after(itinerary.finalUnloadTime());
92 89
   }
93 90
 

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/Voyage.java 查看文件

@@ -54,7 +54,7 @@ public class Voyage implements Entity<Voyage> {
54 54
     final List<CarrierMovement> carrierMovements = new ArrayList<CarrierMovement>(size);
55 55
 
56 56
     for (CarrierMovement carrierMovement : schedule.carrierMovements()) {
57
-      if (carrierMovement.departureLocation().sameIdentityAs(location)) {
57
+      if (carrierMovement.departureLocation().sameAs(location)) {
58 58
         carrierMovements.add(carrierMovement.withDepartureTime(newDepartureTime));
59 59
       } else {
60 60
         carrierMovements.add(carrierMovement);
@@ -77,11 +77,11 @@ public class Voyage implements Entity<Voyage> {
77 77
 
78 78
     final Voyage that = (Voyage) o;
79 79
 
80
-    return sameIdentityAs(that);
80
+    return sameAs(that);
81 81
   }
82 82
 
83 83
   @Override
84
-  public boolean sameIdentityAs(Voyage other) {
84
+  public boolean sameAs(Voyage other) {
85 85
     return other != null && this.voyageNumber().sameValueAs(other.voyageNumber());
86 86
   }
87 87
 

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

@@ -11,6 +11,6 @@ public interface Entity<T> {
11 11
    * @param other The other entity.
12 12
    * @return true if the identities are the same, regardles of other attributes.
13 13
    */
14
-  boolean sameIdentityAs(T other);
14
+  boolean sameAs(T other);
15 15
 
16 16
 }