Skip to content

Commit 99de934

Browse files
committed
Merged PR "rename names in pathfiner package" with Spring Boot changes.
1 parent 0602c4e commit 99de934

File tree

8 files changed

+83
-70
lines changed

8 files changed

+83
-70
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.pathfinder.api;
22

3+
import java.rmi.Remote;
4+
import java.rmi.RemoteException;
35
import java.util.List;
46
import java.util.Properties;
57

@@ -8,16 +10,17 @@
810
* and used by us (booking and tracking team).
911
*
1012
*/
11-
public interface GraphTraversalService {
13+
public interface GraphTraversalService extends Remote {
1214

1315
/**
14-
* @param originUnLocode origin UN Locode
15-
* @param destinationUnLocode destination UN Locode
16+
* @param origin origin point
17+
* @param destination destination point
1618
* @param limitations restrictions on the path selection, as key-value according to some API specification
17-
* @return A list of transit pathss
19+
* @return A list of transit paths
20+
* @throws RemoteException RMI problem
1821
*/
19-
List<TransitPath> findShortestPath(String originUnLocode,
20-
String destinationUnLocode,
22+
List<TransitPath> findShortestPath(String origin,
23+
String destination,
2124
Properties limitations);
2225

2326
}

src/main/java/com/pathfinder/api/TransitEdge.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,43 @@
1010
*/
1111
public final class TransitEdge implements Serializable {
1212

13-
private final String voyageNumber;
14-
private final String fromUnLocode;
15-
private final String toUnLocode;
13+
private final String edge;
14+
private final String fromNode;
15+
private final String toNode;
1616
private final Date fromDate;
1717
private final Date toDate;
1818

1919
/**
2020
* Constructor.
2121
*
22-
* @param voyageNumber
23-
* @param fromUnLocode
24-
* @param toUnLocode
22+
* @param edge
23+
* @param fromNode
24+
* @param toNode
2525
* @param fromDate
2626
* @param toDate
2727
*/
28-
public TransitEdge(final String voyageNumber,
29-
final String fromUnLocode,
30-
final String toUnLocode,
28+
public TransitEdge(final String edge,
29+
final String fromNode,
30+
final String toNode,
3131
final Date fromDate,
3232
final Date toDate) {
33-
this.voyageNumber = voyageNumber;
34-
this.fromUnLocode = fromUnLocode;
35-
this.toUnLocode = toUnLocode;
33+
this.edge = edge;
34+
this.fromNode = fromNode;
35+
this.toNode = toNode;
3636
this.fromDate = fromDate;
3737
this.toDate = toDate;
3838
}
3939

40-
public String getVoyageNumber() {
41-
return voyageNumber;
40+
public String getEdge() {
41+
return edge;
4242
}
4343

44-
public String getFromUnLocode() {
45-
return fromUnLocode;
44+
public String getFromNode() {
45+
return fromNode;
4646
}
4747

48-
public String getToUnLocode() {
49-
return toUnLocode;
48+
public String getToNode() {
49+
return toNode;
5050
}
5151

5252
public Date getFromDate() {

src/main/java/com/pathfinder/config/PathfinderApplicationContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.pathfinder.api.GraphTraversalService;
44
import com.pathfinder.internal.GraphDAO;
5+
import com.pathfinder.internal.GraphDAOStub;
56
import com.pathfinder.internal.GraphTraversalServiceImpl;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.Configuration;
@@ -10,7 +11,7 @@
1011
public class PathfinderApplicationContext {
1112

1213
private GraphDAO graphDAO() {
13-
return new GraphDAO();
14+
return new GraphDAOStub();
1415
}
1516

1617
@Bean
Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
package com.pathfinder.internal;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
53
import java.util.List;
6-
import java.util.Random;
74

8-
public class GraphDAO {
9-
10-
private static final Random random = new Random();
11-
12-
public List<String> listLocations() {
13-
return new ArrayList<String>(Arrays.asList(
14-
"CNHKG", "AUMEL", "SESTO", "FIHEL", "USCHI", "JNTKO", "DEHAM", "CNSHA", "NLRTM", "SEGOT", "CNHGH", "USNYC", "USDAL"
15-
));
16-
}
17-
18-
public String getVoyageNumber(String from, String to) {
19-
final int i = random.nextInt(5);
20-
if (i == 0) return "0100S";
21-
if (i == 1) return "0200T";
22-
if (i == 2) return "0300A";
23-
if (i == 3) return "0301S";
24-
return "0400S";
25-
}
26-
5+
public interface GraphDAO {
6+
List<String> listAllNodes();
7+
String getTransitEdge(String from, String to);
278
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.pathfinder.internal;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Random;
7+
8+
public class GraphDAOStub implements GraphDAO{
9+
10+
private static final Random random = new Random();
11+
12+
public List<String> listAllNodes() {
13+
return new ArrayList<String>(Arrays.asList(
14+
"CNHKG", "AUMEL", "SESTO", "FIHEL", "USCHI", "JNTKO", "DEHAM", "CNSHA", "NLRTM", "SEGOT", "CNHGH", "USNYC", "USDAL"
15+
));
16+
}
17+
18+
public String getTransitEdge(String from, String to) {
19+
final int i = random.nextInt(5);
20+
if (i == 0) return "0100S";
21+
if (i == 1) return "0200T";
22+
if (i == 2) return "0300A";
23+
if (i == 3) return "0301S";
24+
return "0400S";
25+
}
26+
27+
}

src/main/java/com/pathfinder/internal/GraphTraversalServiceImpl.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ public GraphTraversalServiceImpl(GraphDAO dao) {
1818
this.random = new Random();
1919
}
2020

21-
public List<TransitPath> findShortestPath(final String originUnLocode,
22-
final String destinationUnLocode,
21+
public List<TransitPath> findShortestPath(final String originNode,
22+
final String destinationNode,
2323
final Properties limitations) {
2424
Date date = nextDate(new Date());
2525

26-
List<String> allVertices = dao.listLocations();
27-
allVertices.remove(originUnLocode);
28-
allVertices.remove(destinationUnLocode);
26+
List<String> allVertices = dao.listAllNodes();
27+
allVertices.remove(originNode);
28+
allVertices.remove(destinationNode);
2929

3030
final int candidateCount = getRandomNumberOfCandidates();
3131
final List<TransitPath> candidates = new ArrayList<TransitPath>(candidateCount);
3232

3333
for (int i = 0; i < candidateCount; i++) {
34-
allVertices = getRandomChunkOfLocations(allVertices);
34+
allVertices = getRandomChunkOfNodes(allVertices);
3535
final List<TransitEdge> transitEdges = new ArrayList<TransitEdge>(allVertices.size() - 1);
3636
final String firstLegTo = allVertices.get(0);
3737

@@ -40,24 +40,24 @@ public List<TransitPath> findShortestPath(final String originUnLocode,
4040
date = nextDate(toDate);
4141

4242
transitEdges.add(new TransitEdge(
43-
dao.getVoyageNumber(originUnLocode, firstLegTo),
44-
originUnLocode, firstLegTo, fromDate, toDate));
43+
dao.getTransitEdge(originNode, firstLegTo),
44+
originNode, firstLegTo, fromDate, toDate));
4545

4646
for (int j = 0; j < allVertices.size() - 1; j++) {
4747
final String curr = allVertices.get(j);
4848
final String next = allVertices.get(j + 1);
4949
fromDate = nextDate(date);
5050
toDate = nextDate(fromDate);
5151
date = nextDate(toDate);
52-
transitEdges.add(new TransitEdge(dao.getVoyageNumber(curr, next), curr, next, fromDate, toDate));
52+
transitEdges.add(new TransitEdge(dao.getTransitEdge(curr, next), curr, next, fromDate, toDate));
5353
}
5454

5555
final String lastLegFrom = allVertices.get(allVertices.size() - 1);
5656
fromDate = nextDate(date);
5757
toDate = nextDate(fromDate);
5858
transitEdges.add(new TransitEdge(
59-
dao.getVoyageNumber(lastLegFrom, destinationUnLocode),
60-
lastLegFrom, destinationUnLocode, fromDate, toDate));
59+
dao.getTransitEdge(lastLegFrom, destinationNode),
60+
lastLegFrom, destinationNode, fromDate, toDate));
6161

6262
candidates.add(new TransitPath(transitEdges));
6363
}
@@ -73,11 +73,11 @@ private int getRandomNumberOfCandidates() {
7373
return 3 + random.nextInt(3);
7474
}
7575

76-
private List<String> getRandomChunkOfLocations(List<String> allLocations) {
77-
Collections.shuffle(allLocations);
78-
final int total = allLocations.size();
76+
private List<String> getRandomChunkOfNodes(List<String> allNodes) {
77+
Collections.shuffle(allNodes);
78+
final int total = allNodes.size();
7979
final int chunk = total > 4 ? 1 + new Random().nextInt(5) : total;
80-
return allLocations.subList(0, chunk);
80+
return allNodes.subList(0, chunk);
8181
}
8282

8383
}

src/main/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ private Itinerary toItinerary(TransitPath transitPath) {
7777

7878
private Leg toLeg(TransitEdge edge) {
7979
return new Leg(
80-
voyageRepository.find(new VoyageNumber(edge.getVoyageNumber())),
81-
locationRepository.find(new UnLocode(edge.getFromUnLocode())),
82-
locationRepository.find(new UnLocode(edge.getToUnLocode())),
80+
voyageRepository.find(new VoyageNumber(edge.getEdge())),
81+
locationRepository.find(new UnLocode(edge.getFromNode())),
82+
locationRepository.find(new UnLocode(edge.getToNode())),
8383
edge.getFromDate(), edge.getToDate()
8484
);
8585
}

src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package se.citerus.dddsample.infrastructure.routing;
22

33
import com.pathfinder.api.GraphTraversalService;
4-
import com.pathfinder.internal.GraphDAO;
4+
import com.pathfinder.internal.GraphDAOStub;
55
import com.pathfinder.internal.GraphTraversalServiceImpl;
66
import junit.framework.TestCase;
7-
import static org.easymock.EasyMock.*;
87
import se.citerus.dddsample.domain.model.cargo.*;
98
import se.citerus.dddsample.domain.model.location.Location;
109
import se.citerus.dddsample.domain.model.location.LocationRepository;
11-
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
1210
import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
1311
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
1412
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
@@ -18,6 +16,9 @@
1816
import java.util.Date;
1917
import java.util.List;
2018

19+
import static org.easymock.EasyMock.*;
20+
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
21+
2122
public class ExternalRoutingServiceTest extends TestCase {
2223

2324
private ExternalRoutingService externalRoutingService;
@@ -31,8 +32,8 @@ protected void setUp() throws Exception {
3132
voyageRepository = createMock(VoyageRepository.class);
3233
externalRoutingService.setVoyageRepository(voyageRepository);
3334

34-
GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAO() {
35-
public List<String> listLocations() {
35+
GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAOStub() {
36+
public List<String> listAllNodes() {
3637
return Arrays.asList(TOKYO.unLocode().idString(), STOCKHOLM.unLocode().idString(), GOTHENBURG.unLocode().idString());
3738
}
3839

0 commit comments

Comments
 (0)