Bladeren bron

Refactored code to remove warnings

Decker108 11 jaren geleden
bovenliggende
commit
e6ca23b5f0

+ 4
- 8
src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java Bestand weergeven

@@ -19,15 +19,15 @@ public class HandlingHistory implements ValueObject<HandlingHistory> {
19 19
   public HandlingHistory(Collection<HandlingEvent> handlingEvents) {
20 20
     Validate.notNull(handlingEvents, "Handling events are required");
21 21
 
22
-    this.handlingEvents = new ArrayList<HandlingEvent>(handlingEvents);
22
+    this.handlingEvents = new ArrayList<>(handlingEvents);
23 23
   }
24 24
 
25 25
   /**
26 26
    * @return A distinct list (no duplicate registrations) of handling events, ordered by completion time.
27 27
    */
28 28
   public List<HandlingEvent> distinctEventsByCompletionTime() {
29
-    final List<HandlingEvent> ordered = new ArrayList<HandlingEvent>(
30
-      new HashSet<HandlingEvent>(handlingEvents)
29
+    final List<HandlingEvent> ordered = new ArrayList<>(
30
+            new HashSet<>(handlingEvents)
31 31
     );
32 32
     sort(ordered, BY_COMPLETION_TIME_COMPARATOR);
33 33
     return Collections.unmodifiableList(ordered);
@@ -65,10 +65,6 @@ public class HandlingHistory implements ValueObject<HandlingHistory> {
65 65
   }
66 66
 
67 67
   private static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR =
68
-    new Comparator<HandlingEvent>() {
69
-      public int compare(final HandlingEvent he1, final HandlingEvent he2) {
70
-        return he1.completionTime().compareTo(he2.completionTime());
71
-      }
72
-    };
68
+          (he1, he2) -> he1.completionTime().compareTo(he2.completionTime());
73 69
 
74 70
 }

+ 4
- 4
src/main/java/se/citerus/dddsample/domain/model/voyage/SampleVoyages.java Bestand weergeven

@@ -20,8 +20,8 @@ public class SampleVoyages {
20 20
   public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
21 21
   public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
22 22
   private static Voyage createVoyage(String id, Location from, Location to) {
23
-    return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
24
-      new CarrierMovement(from, to, new Date(), new Date())
23
+    return new Voyage(new VoyageNumber(id), new Schedule(Collections.singletonList(
24
+            new CarrierMovement(from, to, new Date(), new Date())
25 25
     )));
26 26
   }
27 27
 
@@ -108,7 +108,7 @@ public class SampleVoyages {
108 108
       addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
109 109
       build();
110 110
 
111
-  public static final Map<VoyageNumber, Voyage> ALL = new HashMap();
111
+  public static final Map<VoyageNumber, Voyage> ALL = new HashMap<>();
112 112
 
113 113
   static {
114 114
     for (Field field : SampleVoyages.class.getDeclaredFields()) {
@@ -124,7 +124,7 @@ public class SampleVoyages {
124 124
   }
125 125
 
126 126
   public static List<Voyage> getAll() {
127
-    return new ArrayList(ALL.values());
127
+    return new ArrayList<>(ALL.values());
128 128
   }
129 129
 
130 130
   public static Voyage lookup(VoyageNumber voyageNumber) {

+ 1
- 5
src/main/java/se/citerus/dddsample/interfaces/booking/web/RouteAssignmentCommand.java Bestand weergeven

@@ -78,11 +78,7 @@ public class RouteAssignmentCommand {
78 78
     }
79 79
 
80 80
     public static Factory factory() {
81
-      return new Factory() {
82
-        public Object create() {
83
-          return new LegCommand();
84
-        }
85
-      };
81
+      return LegCommand::new;
86 82
     }
87 83
 
88 84
   }

+ 2
- 4
src/main/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingController.java Bestand weergeven

@@ -2,11 +2,9 @@ package se.citerus.dddsample.interfaces.tracking;
2 2
 
3 3
 import org.springframework.context.MessageSource;
4 4
 import org.springframework.stereotype.Controller;
5
-import org.springframework.validation.BindException;
6 5
 import org.springframework.validation.BindingResult;
7
-import org.springframework.validation.Errors;
8
-import org.springframework.web.bind.WebDataBinder;
9
-import org.springframework.web.bind.annotation.*;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RequestMethod;
10 8
 import org.springframework.web.servlet.support.RequestContextUtils;
11 9
 import se.citerus.dddsample.domain.model.cargo.Cargo;
12 10
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;

+ 7
- 7
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Bestand weergeven

@@ -23,19 +23,19 @@ import se.citerus.dddsample.domain.model.location.UnLocode;
23 23
 import se.citerus.dddsample.domain.model.voyage.Voyage;
24 24
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
25 25
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
26
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
27
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
28
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
29 26
 
30 27
 import javax.sql.DataSource;
31
-
32 28
 import java.lang.reflect.Field;
33
-import java.util.Arrays;
29
+import java.util.Collections;
34 30
 import java.util.Date;
35 31
 import java.util.List;
36 32
 import java.util.Map;
37 33
 
38 34
 import static org.junit.Assert.*;
35
+import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
36
+import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
37
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
38
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
39 39
 
40 40
 @RunWith(SpringJUnit4ClassRunner.class)
41 41
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
@@ -146,7 +146,7 @@ public class CargoRepositoryTest {
146 146
         Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new Date()));
147 147
         cargoRepository.store(cargo);
148 148
 
149
-        cargo.assignToRoute(new Itinerary(Arrays.asList(
149
+        cargo.assignToRoute(new Itinerary(Collections.singletonList(
150 150
                 new Leg(
151 151
                         voyageRepository.find(new VoyageNumber("0101")),
152 152
                         locationRepository.find(STOCKHOLM.unLocode()),
@@ -181,7 +181,7 @@ public class CargoRepositoryTest {
181 181
 
182 182
         Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
183 183
         Location legTo = locationRepository.find(new UnLocode("DEHAM"));
184
-        Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(CM004, legFrom, legTo, new Date(), new Date())));
184
+        Itinerary newItinerary = new Itinerary(Collections.singletonList(new Leg(CM004, legFrom, legTo, new Date(), new Date())));
185 185
 
186 186
         cargo.assignToRoute(newItinerary);
187 187
 

+ 2
- 2
src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java Bestand weergeven

@@ -28,7 +28,7 @@ public class CargoRepositoryInMem implements CargoRepository {
28 28
    * Constructor.
29 29
    */
30 30
   public CargoRepositoryInMem() {
31
-    cargoDb = new HashMap<String, Cargo>();
31
+    cargoDb = new HashMap<>();
32 32
   }
33 33
 
34 34
   public Cargo find(final TrackingId trackingId) {
@@ -47,7 +47,7 @@ public class CargoRepositoryInMem implements CargoRepository {
47 47
   }
48 48
 
49 49
   public List<Cargo> findAll() {
50
-    return new ArrayList(cargoDb.values());
50
+    return new ArrayList<>(cargoDb.values());
51 51
   }
52 52
 
53 53
   public void init() throws Exception {

+ 0
- 1
src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java Bestand weergeven

@@ -1,6 +1,5 @@
1 1
 package se.citerus.dddsample.interfaces.booking.web;
2 2
 
3
-import junit.framework.TestCase;
4 3
 import org.junit.Test;
5 4
 import org.springframework.mock.web.MockHttpServletRequest;
6 5
 import org.springframework.web.bind.ServletRequestDataBinder;