diff options
Diffstat (limited to 'Week14 Route 66/src/OO14route66/Regelaar.java')
-rw-r--r-- | Week14 Route 66/src/OO14route66/Regelaar.java | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/Week14 Route 66/src/OO14route66/Regelaar.java b/Week14 Route 66/src/OO14route66/Regelaar.java deleted file mode 100644 index bf4cbfd..0000000 --- a/Week14 Route 66/src/OO14route66/Regelaar.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package OO14route66; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author pieterkoopman - */ -public class Regelaar { - - private static Regelaar instance; - - Map<Car, Integer> locations; - - protected Regelaar() { - locations = new HashMap<>(); - } - - public static Regelaar getInstance() { - if (instance == null) { - instance = new Regelaar(); - } - return instance; - } - - public synchronized void setLocation(Car car, int location) { - if (locations.containsKey(car)) { - locations.remove(car); - } - locations.put(car, location); - } - - public synchronized boolean isSafeLocation(Car car, int requested_location) { - for (Map.Entry<Car, Integer> location : locations.entrySet()) { - Car that_car = location.getKey(); - if (that_car != car && - that_car.getDirection() == car.getDirection() && - that_car.getLocation() > requested_location && - that_car.getLocation() < requested_location + Car.CARLENGTH + Car.MINCARSPACE) { - return false; - } - } - return true; - } - -} |