Skip to content

Commit 82badfb

Browse files
author
Decker108
committed
Fixed incorrect indentation
1 parent e6ca23b commit 82badfb

File tree

4 files changed

+269
-268
lines changed

4 files changed

+269
-268
lines changed

src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,67 @@
44
import se.citerus.dddsample.domain.shared.ValueObject;
55

66
import java.util.*;
7+
78
import static java.util.Collections.sort;
89

910
/**
1011
* The handling history of a cargo.
11-
*
1212
*/
1313
public class HandlingHistory implements ValueObject<HandlingHistory> {
1414

15-
private final List<HandlingEvent> handlingEvents;
16-
17-
public static final HandlingHistory EMPTY = new HandlingHistory(Collections.<HandlingEvent>emptyList());
18-
19-
public HandlingHistory(Collection<HandlingEvent> handlingEvents) {
20-
Validate.notNull(handlingEvents, "Handling events are required");
21-
22-
this.handlingEvents = new ArrayList<>(handlingEvents);
23-
}
24-
25-
/**
26-
* @return A distinct list (no duplicate registrations) of handling events, ordered by completion time.
27-
*/
28-
public List<HandlingEvent> distinctEventsByCompletionTime() {
29-
final List<HandlingEvent> ordered = new ArrayList<>(
30-
new HashSet<>(handlingEvents)
31-
);
32-
sort(ordered, BY_COMPLETION_TIME_COMPARATOR);
33-
return Collections.unmodifiableList(ordered);
34-
}
35-
36-
/**
37-
* @return Most recently completed event, or null if the delivery history is empty.
38-
*/
39-
public HandlingEvent mostRecentlyCompletedEvent() {
40-
final List<HandlingEvent> distinctEvents = distinctEventsByCompletionTime();
41-
if (distinctEvents.isEmpty()) {
42-
return null;
43-
} else {
44-
return distinctEvents.get(distinctEvents.size() - 1);
15+
private final List<HandlingEvent> handlingEvents;
16+
17+
public static final HandlingHistory EMPTY = new HandlingHistory(Collections.<HandlingEvent>emptyList());
18+
19+
public HandlingHistory(Collection<HandlingEvent> handlingEvents) {
20+
Validate.notNull(handlingEvents, "Handling events are required");
21+
22+
this.handlingEvents = new ArrayList<>(handlingEvents);
4523
}
46-
}
4724

48-
@Override
49-
public boolean sameValueAs(HandlingHistory other) {
50-
return other != null && this.handlingEvents.equals(other.handlingEvents);
51-
}
25+
/**
26+
* @return A distinct list (no duplicate registrations) of handling events, ordered by completion time.
27+
*/
28+
public List<HandlingEvent> distinctEventsByCompletionTime() {
29+
final List<HandlingEvent> ordered = new ArrayList<>(
30+
new HashSet<>(handlingEvents)
31+
);
32+
sort(ordered, BY_COMPLETION_TIME_COMPARATOR);
33+
return Collections.unmodifiableList(ordered);
34+
}
5235

53-
@Override
54-
public boolean equals(Object o) {
55-
if (this == o) return true;
56-
if (o == null || getClass() != o.getClass()) return false;
36+
/**
37+
* @return Most recently completed event, or null if the delivery history is empty.
38+
*/
39+
public HandlingEvent mostRecentlyCompletedEvent() {
40+
final List<HandlingEvent> distinctEvents = distinctEventsByCompletionTime();
41+
if (distinctEvents.isEmpty()) {
42+
return null;
43+
} else {
44+
return distinctEvents.get(distinctEvents.size() - 1);
45+
}
46+
}
5747

58-
final HandlingHistory other = (HandlingHistory) o;
59-
return sameValueAs(other);
60-
}
48+
@Override
49+
public boolean sameValueAs(HandlingHistory other) {
50+
return other != null && this.handlingEvents.equals(other.handlingEvents);
51+
}
52+
53+
@Override
54+
public boolean equals(Object o) {
55+
if (this == o) return true;
56+
if (o == null || getClass() != o.getClass()) return false;
6157

62-
@Override
63-
public int hashCode() {
64-
return handlingEvents.hashCode();
65-
}
58+
final HandlingHistory other = (HandlingHistory) o;
59+
return sameValueAs(other);
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return handlingEvents.hashCode();
65+
}
6666

67-
private static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR =
68-
(he1, he2) -> he1.completionTime().compareTo(he2.completionTime());
67+
private static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR =
68+
(he1, he2) -> he1.completionTime().compareTo(he2.completionTime());
6969

7070
}
Lines changed: 116 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,135 @@
11
package se.citerus.dddsample.domain.model.voyage;
22

33
import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
4+
45
import se.citerus.dddsample.domain.model.location.Location;
6+
57
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
68

79
import java.lang.reflect.Field;
810
import java.util.*;
911

1012
/**
1113
* Sample carrier movements, for test purposes.
12-
*
1314
*/
1415
public class SampleVoyages {
1516

16-
public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
17-
public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
18-
public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
19-
public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
20-
public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
21-
public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
22-
private static Voyage createVoyage(String id, Location from, Location to) {
23-
return new Voyage(new VoyageNumber(id), new Schedule(Collections.singletonList(
24-
new CarrierMovement(from, to, new Date(), new Date())
25-
)));
26-
}
27-
28-
// TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
29-
30-
public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
31-
addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
32-
addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-09")).
33-
build();
34-
public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), TOKYO).
35-
addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
36-
addMovement(CHICAGO, toDate("2009-03-10"), toDate("2009-03-14")).
37-
addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
38-
build();
39-
public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
40-
addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
41-
addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
42-
addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
43-
addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
44-
build();
45-
public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
46-
addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
47-
addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
48-
addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
49-
build();
50-
51-
/**
52-
* Voyage number 0100S (by ship)
53-
*
54-
* Hongkong - Hangzou - Tokyo - Melbourne - New York
55-
*/
56-
public static final Voyage HONGKONG_TO_NEW_YORK =
57-
new Voyage.Builder(new VoyageNumber("0100S"), HONGKONG).
58-
addMovement(HANGZOU, toDate("2008-10-01", "12:00"), toDate("2008-10-03", "14:30")).
59-
addMovement(TOKYO, toDate("2008-10-03", "21:00"), toDate("2008-10-06", "06:15")).
60-
addMovement(MELBOURNE, toDate("2008-10-06", "11:00"), toDate("2008-10-12", "11:30")).
61-
addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10")).
62-
build();
63-
64-
65-
/**
66-
* Voyage number 0200T (by train)
67-
*
68-
* New York - Chicago - Dallas
69-
*/
70-
public static final Voyage NEW_YORK_TO_DALLAS =
71-
new Voyage.Builder(new VoyageNumber("0200T"), NEWYORK).
72-
addMovement(CHICAGO, toDate("2008-10-24", "07:00"), toDate("2008-10-24", "17:45")).
73-
addMovement(DALLAS, toDate("2008-10-24", "21:25"), toDate("2008-10-25", "19:30")).
74-
build();
75-
76-
/**
77-
* Voyage number 0300A (by airplane)
78-
*
79-
* Dallas - Hamburg - Stockholm - Helsinki
80-
*/
81-
public static final Voyage DALLAS_TO_HELSINKI =
82-
new Voyage.Builder(new VoyageNumber("0300A"), DALLAS).
83-
addMovement(HAMBURG, toDate("2008-10-29", "03:30"), toDate("2008-10-31", "14:00")).
84-
addMovement(STOCKHOLM, toDate("2008-11-01", "15:20"), toDate("2008-11-01", "18:40")).
85-
addMovement(HELSINKI, toDate("2008-11-02", "09:00"), toDate("2008-11-02", "11:15")).
86-
build();
87-
88-
/**
89-
* Voyage number 0301S (by ship)
90-
*
91-
* Dallas - Hamburg - Stockholm - Helsinki, alternate route
92-
*/
93-
public static final Voyage DALLAS_TO_HELSINKI_ALT =
94-
new Voyage.Builder(new VoyageNumber("0301S"), DALLAS).
95-
addMovement(HELSINKI, toDate("2008-10-29", "03:30"), toDate("2008-11-05", "15:45")).
96-
build();
97-
98-
/**
99-
* Voyage number 0400S (by ship)
100-
*
101-
* Helsinki - Rotterdam - Shanghai - Hongkong
102-
*
103-
*/
104-
public static final Voyage HELSINKI_TO_HONGKONG =
105-
new Voyage.Builder(new VoyageNumber("0400S"), HELSINKI).
106-
addMovement(ROTTERDAM, toDate("2008-11-04", "05:50"), toDate("2008-11-06", "14:10")).
107-
addMovement(SHANGHAI, toDate("2008-11-10", "21:45"), toDate("2008-11-22", "16:40")).
108-
addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
109-
build();
110-
111-
public static final Map<VoyageNumber, Voyage> ALL = new HashMap<>();
112-
113-
static {
114-
for (Field field : SampleVoyages.class.getDeclaredFields()) {
115-
if (field.getType().equals(Voyage.class)) {
116-
try {
117-
Voyage voyage = (Voyage) field.get(null);
118-
ALL.put(voyage.voyageNumber(), voyage);
119-
} catch (IllegalAccessException e) {
120-
throw new RuntimeException(e);
17+
public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
18+
public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
19+
public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
20+
public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
21+
public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
22+
public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
23+
24+
private static Voyage createVoyage(String id, Location from, Location to) {
25+
return new Voyage(new VoyageNumber(id), new Schedule(Collections.singletonList(
26+
new CarrierMovement(from, to, new Date(), new Date())
27+
)));
28+
}
29+
30+
// TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
31+
32+
public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
33+
addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
34+
addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-09")).
35+
build();
36+
public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), TOKYO).
37+
addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
38+
addMovement(CHICAGO, toDate("2009-03-10"), toDate("2009-03-14")).
39+
addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
40+
build();
41+
public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
42+
addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
43+
addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
44+
addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
45+
addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
46+
build();
47+
public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
48+
addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
49+
addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
50+
addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
51+
build();
52+
53+
/**
54+
* Voyage number 0100S (by ship)
55+
* <p>
56+
* Hongkong - Hangzou - Tokyo - Melbourne - New York
57+
*/
58+
public static final Voyage HONGKONG_TO_NEW_YORK =
59+
new Voyage.Builder(new VoyageNumber("0100S"), HONGKONG).
60+
addMovement(HANGZOU, toDate("2008-10-01", "12:00"), toDate("2008-10-03", "14:30")).
61+
addMovement(TOKYO, toDate("2008-10-03", "21:00"), toDate("2008-10-06", "06:15")).
62+
addMovement(MELBOURNE, toDate("2008-10-06", "11:00"), toDate("2008-10-12", "11:30")).
63+
addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10")).
64+
build();
65+
66+
67+
/**
68+
* Voyage number 0200T (by train)
69+
* <p>
70+
* New York - Chicago - Dallas
71+
*/
72+
public static final Voyage NEW_YORK_TO_DALLAS =
73+
new Voyage.Builder(new VoyageNumber("0200T"), NEWYORK).
74+
addMovement(CHICAGO, toDate("2008-10-24", "07:00"), toDate("2008-10-24", "17:45")).
75+
addMovement(DALLAS, toDate("2008-10-24", "21:25"), toDate("2008-10-25", "19:30")).
76+
build();
77+
78+
/**
79+
* Voyage number 0300A (by airplane)
80+
* <p>
81+
* Dallas - Hamburg - Stockholm - Helsinki
82+
*/
83+
public static final Voyage DALLAS_TO_HELSINKI =
84+
new Voyage.Builder(new VoyageNumber("0300A"), DALLAS).
85+
addMovement(HAMBURG, toDate("2008-10-29", "03:30"), toDate("2008-10-31", "14:00")).
86+
addMovement(STOCKHOLM, toDate("2008-11-01", "15:20"), toDate("2008-11-01", "18:40")).
87+
addMovement(HELSINKI, toDate("2008-11-02", "09:00"), toDate("2008-11-02", "11:15")).
88+
build();
89+
90+
/**
91+
* Voyage number 0301S (by ship)
92+
* <p>
93+
* Dallas - Hamburg - Stockholm - Helsinki, alternate route
94+
*/
95+
public static final Voyage DALLAS_TO_HELSINKI_ALT =
96+
new Voyage.Builder(new VoyageNumber("0301S"), DALLAS).
97+
addMovement(HELSINKI, toDate("2008-10-29", "03:30"), toDate("2008-11-05", "15:45")).
98+
build();
99+
100+
/**
101+
* Voyage number 0400S (by ship)
102+
* <p>
103+
* Helsinki - Rotterdam - Shanghai - Hongkong
104+
*/
105+
public static final Voyage HELSINKI_TO_HONGKONG =
106+
new Voyage.Builder(new VoyageNumber("0400S"), HELSINKI).
107+
addMovement(ROTTERDAM, toDate("2008-11-04", "05:50"), toDate("2008-11-06", "14:10")).
108+
addMovement(SHANGHAI, toDate("2008-11-10", "21:45"), toDate("2008-11-22", "16:40")).
109+
addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
110+
build();
111+
112+
public static final Map<VoyageNumber, Voyage> ALL = new HashMap<>();
113+
114+
static {
115+
for (Field field : SampleVoyages.class.getDeclaredFields()) {
116+
if (field.getType().equals(Voyage.class)) {
117+
try {
118+
Voyage voyage = (Voyage) field.get(null);
119+
ALL.put(voyage.voyageNumber(), voyage);
120+
} catch (IllegalAccessException e) {
121+
throw new RuntimeException(e);
122+
}
123+
}
121124
}
122-
}
123125
}
124-
}
125126

126-
public static List<Voyage> getAll() {
127-
return new ArrayList<>(ALL.values());
128-
}
127+
public static List<Voyage> getAll() {
128+
return new ArrayList<>(ALL.values());
129+
}
130+
131+
public static Voyage lookup(VoyageNumber voyageNumber) {
132+
return ALL.get(voyageNumber);
133+
}
129134

130-
public static Voyage lookup(VoyageNumber voyageNumber) {
131-
return ALL.get(voyageNumber);
132-
}
133-
134135
}

0 commit comments

Comments
 (0)