diff --git a/src/Street.java b/src/Street.java index 9b4f3bd..36bdb04 100644 --- a/src/Street.java +++ b/src/Street.java @@ -1,21 +1,33 @@ import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; public class Street { private double length; private int numberOfLanes; - private ArrayList vehicles; + private ArrayList vehicles; //Current + private HashMap> vehiclesHistory;//History of vehicles private StreetNames name; public Street(double length, int numberOfLanes, StreetNames name) { vehicles = new ArrayList<>(); + vehiclesHistory = new HashMap<>(); setLength(length); setNumberOfLanes(numberOfLanes); this.name = name; } + public Date[] getHistoryForVehicle(Vehicle vehicle){ + if (vehiclesHistory.containsKey(vehicle)){ + Date[] hist = new Date[vehiclesHistory.get(vehicle).size()]; + return vehiclesHistory.get(vehicle).toArray(hist); + } + return null; + } + private void setLength(double length) { if (length >= 0) this.length = length; else throw new IllegalArgumentException("Can not make a negative length street"); @@ -83,10 +95,15 @@ public class Street { } public void addVehicle(Vehicle vehicle) { - //if(capcity() > vehicle.getVehicleSize() + 0.5) { - //adds incoming vehicle in last. - vehicles.add(vehicle); - //} + vehicles.add(vehicle); + addHistoryEntry(vehicle); + } + + private void addHistoryEntry(Vehicle vehicle) { + if (!vehiclesHistory.containsKey(vehicle)) { + vehiclesHistory.put(vehicle, new ArrayList<>()); + } + vehiclesHistory.get(vehicle).add(MakkahCity.getTimeMan().getCurrentTime());//Add time } public double capcityPoint(double min, double max) {