diff options
Diffstat (limited to 'src/main/java/com/benburwell/planes/graph')
-rw-r--r-- | src/main/java/com/benburwell/planes/graph/Airway.java | 29 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/graph/RouteGraph.java | 29 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/com/benburwell/planes/graph/Airway.java b/src/main/java/com/benburwell/planes/graph/Airway.java new file mode 100644 index 0000000..0a40d45 --- /dev/null +++ b/src/main/java/com/benburwell/planes/graph/Airway.java @@ -0,0 +1,29 @@ +package com.benburwell.planes.graph; + +import com.benburwell.planes.data.Position; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author ben + */ +public class Airway { + private String code; + private List<Position> points = new ArrayList<>(); + + public Airway(String code) { + this.code = code; + } + + public void addPoint(double latitude, double longitude) { + Position pos = new Position(); + pos.setLatitude(latitude); + pos.setLongitude(longitude); + this.points.add(pos); + } + + public List<Position> getPoints() { + return this.points; + } +} diff --git a/src/main/java/com/benburwell/planes/graph/RouteGraph.java b/src/main/java/com/benburwell/planes/graph/RouteGraph.java new file mode 100644 index 0000000..34048ac --- /dev/null +++ b/src/main/java/com/benburwell/planes/graph/RouteGraph.java @@ -0,0 +1,29 @@ +package com.benburwell.planes.graph; + +import com.benburwell.planes.data.Intersection; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * @author ben + */ +public class RouteGraph { + private Map<String,Airway> airways = new HashMap<>(); + + public void addIntersection(Intersection in) { + if (!this.airways.containsKey(in.getAirway1())) { + this.airways.put(in.getAirway1(), new Airway(in.getAirway1())); + } + if (!this.airways.containsKey(in.getAirway2())) { + this.airways.put(in.getAirway2(), new Airway(in.getAirway2())); + } + this.airways.get(in.getAirway1()).addPoint(in.getLatitude(), in.getLongitude()); + this.airways.get(in.getAirway2()).addPoint(in.getLatitude(), in.getLongitude()); + } + + public Collection<Airway> getAirways() { + return this.airways.values(); + } +} |