Skip to content

Commit 02fced3

Browse files
committed
Renamed LegMatch to LegActivityMatch, more in line with the UL
1 parent 3c57243 commit 02fced3

File tree

5 files changed

+59
-55
lines changed

5 files changed

+59
-55
lines changed

dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Itinerary.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import org.apache.commons.lang.StringUtils;
44
import org.apache.commons.lang.Validate;
5-
import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
65
import se.citerus.dddsample.tracking.core.domain.model.location.Location;
76
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
8-
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
9-
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.receiveIn;
107
import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
118
import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
129

1310
import java.util.*;
1411

12+
import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
13+
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
14+
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.receiveIn;
15+
1516
/**
1617
* An itinerary.
1718
*/
@@ -93,7 +94,7 @@ public Itinerary withRescheduledVoyage(final Voyage rescheduledVoyage) {
9394
* @return <code>true</code> if the event is expected
9495
*/
9596
boolean isExpectedActivity(final HandlingActivity handlingActivity) {
96-
return legMatchOf(handlingActivity).leg() != null;
97+
return matchLeg(handlingActivity).leg() != null;
9798
}
9899

99100
/**
@@ -172,7 +173,7 @@ HandlingActivity activitySucceding(final HandlingActivity previousActivity) {
172173
if (previousActivity == null) {
173174
return receiveIn(firstLeg().loadLocation());
174175
} else {
175-
return deriveFromMatchingLeg(previousActivity, legMatchOf(previousActivity).leg());
176+
return deriveFromMatchingLeg(previousActivity, matchLeg(previousActivity).leg());
176177
}
177178
}
178179

@@ -182,8 +183,8 @@ HandlingActivity activitySucceding(final HandlingActivity previousActivity) {
182183
* @return The activity which is strictly prior to the other, according to the itinerary, or null if neither is strictly prior.
183184
*/
184185
HandlingActivity strictlyPriorOf(final HandlingActivity handlingActivity1, final HandlingActivity handlingActivity2) {
185-
final LegMatch match1 = legMatchOf(handlingActivity1);
186-
final LegMatch match2 = legMatchOf(handlingActivity2);
186+
final LegActivityMatch match1 = matchLeg(handlingActivity1);
187+
final LegActivityMatch match2 = matchLeg(handlingActivity2);
187188
final int compared = match1.compareTo(match2);
188189

189190
if (compared < 0) {
@@ -213,13 +214,13 @@ Leg nextLeg(final Leg leg) {
213214
* @param handlingActivity handling activity
214215
* @return The leg match of this handling activity. Never null.
215216
*/
216-
LegMatch legMatchOf(final HandlingActivity handlingActivity) {
217+
LegActivityMatch matchLeg(final HandlingActivity handlingActivity) {
217218
if (handlingActivity == null) {
218-
return LegMatch.noMatch(handlingActivity, this);
219+
return LegActivityMatch.noMatch(handlingActivity, this);
219220
} else if (handlingActivity.type() == RECEIVE) {
220-
return LegMatch.ifLoadLocationSame(firstLeg(), handlingActivity, this);
221+
return LegActivityMatch.ifLoadLocationSame(firstLeg(), handlingActivity, this);
221222
} else if (handlingActivity.type() == CLAIM) {
222-
return LegMatch.ifUnloadLocationSame(lastLeg(), handlingActivity, this);
223+
return LegActivityMatch.ifUnloadLocationSame(lastLeg(), handlingActivity, this);
223224
} else {
224225
return findLegMatchingActivity(handlingActivity);
225226
}
@@ -239,14 +240,14 @@ public Leg lastLeg() {
239240
return legs.get(legs.size() - 1);
240241
}
241242

242-
private LegMatch findLegMatchingActivity(final HandlingActivity handlingActivity) {
243+
private LegActivityMatch findLegMatchingActivity(final HandlingActivity handlingActivity) {
243244
for (Leg leg : legs) {
244245
if (leg.matchesActivity(handlingActivity)) {
245-
return LegMatch.match(leg, handlingActivity, this);
246+
return LegActivityMatch.match(leg, handlingActivity, this);
246247
}
247248
}
248249

249-
return LegMatch.noMatch(handlingActivity, this);
250+
return LegActivityMatch.noMatch(handlingActivity, this);
250251
}
251252

252253
private HandlingActivity deriveFromMatchingLeg(final HandlingActivity handlingActivity, final Leg matchingLeg) {

dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/LegMatch.java renamed to dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/LegActivityMatch.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package se.citerus.dddsample.tracking.core.domain.model.cargo;
22

3-
import static se.citerus.dddsample.tracking.core.domain.model.cargo.LegMatch.LegEnd.*;
43
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
54
import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
65

7-
class LegMatch extends ValueObjectSupport<LegMatch> implements Comparable<LegMatch> {
6+
import static se.citerus.dddsample.tracking.core.domain.model.cargo.LegActivityMatch.LegEnd.*;
7+
8+
class LegActivityMatch extends ValueObjectSupport<LegActivityMatch> implements Comparable<LegActivityMatch> {
89

910
private final Leg leg;
1011
private final LegEnd legEnd;
@@ -13,45 +14,45 @@ class LegMatch extends ValueObjectSupport<LegMatch> implements Comparable<LegMat
1314

1415
enum LegEnd { LOAD_END, UNLOAD_END, NO_END }
1516

16-
private LegMatch(final Leg leg, final LegEnd legEnd, final HandlingActivity handlingActivity, final Itinerary itinerary) {
17+
private LegActivityMatch(final Leg leg, final LegEnd legEnd, final HandlingActivity handlingActivity, final Itinerary itinerary) {
1718
this.leg = leg;
1819
this.legEnd = legEnd;
1920
this.handlingActivity = handlingActivity;
2021
this.itinerary = itinerary;
2122
}
2223

23-
static LegMatch match(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
24+
static LegActivityMatch match(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
2425
switch (handlingActivity.type()) {
2526
case RECEIVE:
2627
case LOAD:
27-
return new LegMatch(leg, LOAD_END, handlingActivity, itinerary);
28+
return new LegActivityMatch(leg, LOAD_END, handlingActivity, itinerary);
2829
case UNLOAD:
2930
case CLAIM:
3031
case CUSTOMS:
31-
return new LegMatch(leg, UNLOAD_END, handlingActivity, itinerary);
32+
return new LegActivityMatch(leg, UNLOAD_END, handlingActivity, itinerary);
3233
default:
3334
return noMatch(handlingActivity, itinerary);
3435
}
3536
}
3637

37-
static LegMatch ifLoadLocationSame(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
38+
static LegActivityMatch ifLoadLocationSame(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
3839
if (leg.loadLocation().sameAs(handlingActivity.location())) {
39-
return new LegMatch(leg, LOAD_END, handlingActivity, itinerary);
40+
return new LegActivityMatch(leg, LOAD_END, handlingActivity, itinerary);
4041
} else {
4142
return noMatch(handlingActivity, itinerary);
4243
}
4344
}
4445

45-
static LegMatch ifUnloadLocationSame(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
46+
static LegActivityMatch ifUnloadLocationSame(final Leg leg, final HandlingActivity handlingActivity, final Itinerary itinerary) {
4647
if (leg.unloadLocation().sameAs(handlingActivity.location())) {
47-
return new LegMatch(leg, UNLOAD_END, handlingActivity, itinerary);
48+
return new LegActivityMatch(leg, UNLOAD_END, handlingActivity, itinerary);
4849
} else {
4950
return noMatch(handlingActivity, itinerary);
5051
}
5152
}
5253

53-
static LegMatch noMatch(final HandlingActivity handlingActivity, final Itinerary itinerary) {
54-
return new LegMatch(null, NO_END, handlingActivity, itinerary);
54+
static LegActivityMatch noMatch(final HandlingActivity handlingActivity, final Itinerary itinerary) {
55+
return new LegActivityMatch(null, NO_END, handlingActivity, itinerary);
5556
}
5657

5758
Leg leg() {
@@ -63,7 +64,7 @@ HandlingActivity handlingActivity() {
6364
}
6465

6566
@Override
66-
public int compareTo(final LegMatch other) {
67+
public int compareTo(final LegActivityMatch other) {
6768
final Integer thisLegIndex = itinerary.legs().indexOf(this.leg);
6869
final Integer otherLegIndex = itinerary.legs().indexOf(other.leg);
6970

dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/CargoTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package se.citerus.dddsample.tracking.core.domain.model.cargo;
22

33
import junit.framework.TestCase;
4+
import se.citerus.dddsample.tracking.core.domain.model.location.Location;
5+
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
6+
import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
7+
import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
8+
9+
import java.util.Date;
10+
411
import static org.hamcrest.core.Is.is;
512
import static org.junit.Assert.assertThat;
613
import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
714
import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
815
import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
916
import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
10-
import se.citerus.dddsample.tracking.core.domain.model.location.Location;
1117
import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
12-
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
1318
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
1419
import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
15-
import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
16-
import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
17-
18-
import java.util.Date;
1920

2021
public class CargoTest extends TestCase {
2122

@@ -269,11 +270,11 @@ public void testIsMisdirectedAfterRerouting() throws Exception {
269270
assertTrue(cargo.routingStatus() == MISROUTED);
270271

271272
/**
272-
* This is a perfect example of how LegMatch is a modelling breakthrough.
273+
* This is a perfect example of how LegActivityMatch is a modelling breakthrough.
273274
* It allows us to easily construct an itinerary that completes the remainder of the
274275
* old itinerary and appends the new and different path.
275276
*/
276-
Leg currentLeg = cargo.itinerary().legMatchOf(cargo.mostRecentHandlingActivity()).leg();
277+
Leg currentLeg = cargo.itinerary().matchLeg(cargo.mostRecentHandlingActivity()).leg();
277278
Itinerary newItinerary = new Itinerary(
278279
currentLeg,
279280
Leg.deriveLeg(continental3, SEATTLE, NEWYORK)

dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/ItineraryTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package se.citerus.dddsample.tracking.core.domain.model.cargo;
22

33
import junit.framework.TestCase;
4-
import static org.hamcrest.core.Is.is;
5-
import static org.hamcrest.core.IsEqual.equalTo;
6-
import static org.junit.Assert.assertThat;
7-
import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
8-
import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
94
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
10-
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
115
import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
126
import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
137

148
import java.util.ArrayList;
159
import java.util.Date;
1610
import java.util.List;
1711

12+
import static org.hamcrest.core.Is.is;
13+
import static org.hamcrest.core.IsEqual.equalTo;
14+
import static org.junit.Assert.assertThat;
15+
import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
16+
import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
17+
import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
18+
1819
public class ItineraryTest extends TestCase {
1920

2021
Voyage voyage, wrongVoyage, pacific, transcontinental, atlantic;
@@ -102,19 +103,19 @@ public void testMatchingLeg() {
102103
Leg rotterdamToGothenburg = Leg.deriveLeg(voyage, ROTTERDAM, GOTHENBURG);
103104
Itinerary itinerary = new Itinerary(shanghaiToRotterdam, rotterdamToGothenburg);
104105

105-
assertThat(itinerary.legMatchOf(receiveIn(SHANGHAI)).leg(), is(shanghaiToRotterdam));
106-
assertThat(itinerary.legMatchOf(loadOnto(voyage).in(SHANGHAI)).leg(), is(shanghaiToRotterdam));
107-
assertThat(itinerary.legMatchOf(unloadOff(voyage).in(ROTTERDAM)).leg(), is(shanghaiToRotterdam));
108-
assertThat(itinerary.legMatchOf(claimIn(GOTHENBURG)).leg(), is(rotterdamToGothenburg));
106+
assertThat(itinerary.matchLeg(receiveIn(SHANGHAI)).leg(), is(shanghaiToRotterdam));
107+
assertThat(itinerary.matchLeg(loadOnto(voyage).in(SHANGHAI)).leg(), is(shanghaiToRotterdam));
108+
assertThat(itinerary.matchLeg(unloadOff(voyage).in(ROTTERDAM)).leg(), is(shanghaiToRotterdam));
109+
assertThat(itinerary.matchLeg(claimIn(GOTHENBURG)).leg(), is(rotterdamToGothenburg));
109110

110-
assertNull(itinerary.legMatchOf(loadOnto(wrongVoyage).in(SHANGHAI)).leg());
111-
assertNull(itinerary.legMatchOf(loadOnto(wrongVoyage).in(NEWYORK)).leg());
111+
assertNull(itinerary.matchLeg(loadOnto(wrongVoyage).in(SHANGHAI)).leg());
112+
assertNull(itinerary.matchLeg(loadOnto(wrongVoyage).in(NEWYORK)).leg());
112113

113-
assertNull(itinerary.legMatchOf(unloadOff(wrongVoyage).in(ROTTERDAM)).leg());
114-
assertNull(itinerary.legMatchOf(unloadOff(wrongVoyage).in(NEWYORK)).leg());
114+
assertNull(itinerary.matchLeg(unloadOff(wrongVoyage).in(ROTTERDAM)).leg());
115+
assertNull(itinerary.matchLeg(unloadOff(wrongVoyage).in(NEWYORK)).leg());
115116

116-
assertNull(itinerary.legMatchOf(receiveIn(NEWYORK)).leg());
117-
assertNull(itinerary.legMatchOf(claimIn(NEWYORK)).leg());
117+
assertNull(itinerary.matchLeg(receiveIn(NEWYORK)).leg());
118+
assertNull(itinerary.matchLeg(claimIn(NEWYORK)).leg());
118119
}
119120

120121
public void testNextLeg() {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.pacific1;
1616

1717
@RunWith(JUnit4ClassRunner.class)
18-
public class LegMatchTest {
18+
public class LegActivityMatchTest {
1919

2020
@Test
2121
public void compareMatches() {
@@ -24,21 +24,21 @@ public void compareMatches() {
2424
deriveLeg(continental2, LONGBEACH, DALLAS)
2525
);
2626

27-
LegMatch startMatch = LegMatch.match(
27+
LegActivityMatch startMatch = LegActivityMatch.match(
2828
deriveLeg(pacific1, TOKYO, LONGBEACH),
2929
loadOnto(pacific1).in(TOKYO), itinerary);
3030

3131
assertThat(startMatch.handlingActivity(), equalTo(loadOnto(pacific1).in(TOKYO)));
3232
assertThat(startMatch.leg(), equalTo(deriveLeg(pacific1, TOKYO, LONGBEACH)));
3333

34-
LegMatch endMatch = LegMatch.match(
34+
LegActivityMatch endMatch = LegActivityMatch.match(
3535
deriveLeg(pacific1, TOKYO, LONGBEACH),
3636
unloadOff(pacific1).in(LONGBEACH), itinerary);
3737

3838
assertThat(endMatch.handlingActivity(), equalTo(unloadOff(pacific1).in(LONGBEACH)));
3939
assertThat(endMatch.leg(), equalTo(deriveLeg(pacific1, TOKYO, LONGBEACH)));
4040

41-
LegMatch nextMatch = LegMatch.match(
41+
LegActivityMatch nextMatch = LegActivityMatch.match(
4242
deriveLeg(continental2, LONGBEACH, DALLAS),
4343
loadOnto(continental2).in(LONGBEACH), itinerary);
4444

0 commit comments

Comments
 (0)