diff --git a/src/main/java/usherbrooke/ift630/App.java b/src/main/java/usherbrooke/ift630/App.java index a316e7d..8a4de42 100644 --- a/src/main/java/usherbrooke/ift630/App.java +++ b/src/main/java/usherbrooke/ift630/App.java @@ -1,19 +1,19 @@ package usherbrooke.ift630; public class App { - static private int numLines = 3; - static private int numBusPerLine = 2; - static private int numBusses = numLines * numBusPerLine; - static private int numStopPerBus = 8; - static private int numStops = numBusses * numStopPerBus; - static private int numPassengersPerBus = 5; + static private int numLines = 3; + static private int numBusPerLine = 2; + static private int numBusses = numLines * numBusPerLine; + static private int numStopPerBus = 8; + static private int numStops = numBusses * numStopPerBus; + static private int numPassengersPerBus = 5; static private int numPassengersPerStop = 5; - //static private int numPassengers = numPassengersPerStop * numStops; - static private int numThreadsBus = 5; - static private int numThreadsStop = 2; - static private int timeBetweenStops = 5; - static private int timeEmbark = 2; - static private int socketPort = 8181; + // static private int numPassengers = numPassengersPerStop * numStops; + static private int numThreadsBus = 5; + static private int numThreadsStop = 2; + static private int timeBetweenStops = 5; + static private int timeEmbark = 2; + static private int socketPort = 8181; public static void main(String[] args) { try { diff --git a/src/main/java/usherbrooke/ift630/Bus.java b/src/main/java/usherbrooke/ift630/Bus.java index 611c4f5..6c8cd1e 100644 --- a/src/main/java/usherbrooke/ift630/Bus.java +++ b/src/main/java/usherbrooke/ift630/Bus.java @@ -64,7 +64,7 @@ public class Bus extends Thread { overMaxCapacity = currentCapacity >= maxCapacity; nextStopEmpty = getNextStopPassengers().isEmpty(); - if (stopAsked()) + if (stopAsked()) Logger.getInstance().print(id, "[BUS] " + name + " stop asked!"); if (overMaxCapacity) { Logger.getInstance().print(id, "[BUS] " + name + " im full, sorry!"); @@ -141,15 +141,15 @@ public class Bus extends Thread { } Bus(Line line, int id, int timeStop, int timeEmbark, int maxCapacity) { - this.timeBetweenStops = timeStop * 1000 + 1; - this.timeEmbark = timeEmbark * 1000 + 1; - this.name = "Bus n°" + id; - this.id = id; - this.passengers = new ArrayList(); - this.line = line; - this.nextStop = line.get(0); - this.currentCapacity = 0; - this.maxCapacity = maxCapacity; + this.timeBetweenStops = timeStop * 1000 + 1; + this.timeEmbark = timeEmbark * 1000 + 1; + this.name = "Bus n°" + id; + this.id = id; + this.passengers = new ArrayList(); + this.line = line; + this.nextStop = line.get(0); + this.currentCapacity = 0; + this.maxCapacity = maxCapacity; } // disembark passenger at a stop. Synchronizes, locks on that stop, and waits. @@ -219,7 +219,8 @@ public class Bus extends Thread { return name; } - // still there since i first didnt understand what a trip should have been. See git logs. + // still there since i first didnt understand what a trip should have been. See + // git logs. public List getStops() { return line.getStops(); } diff --git a/src/main/java/usherbrooke/ift630/ExitException.java b/src/main/java/usherbrooke/ift630/ExitException.java index 7ec3e2d..a1c1906 100644 --- a/src/main/java/usherbrooke/ift630/ExitException.java +++ b/src/main/java/usherbrooke/ift630/ExitException.java @@ -1,7 +1,8 @@ package usherbrooke.ift630; public class ExitException extends Exception { - ExitException() {} + ExitException() { + } public ExitException(String message) { super(message); diff --git a/src/main/java/usherbrooke/ift630/Logger.java b/src/main/java/usherbrooke/ift630/Logger.java index f4812e8..22a663a 100644 --- a/src/main/java/usherbrooke/ift630/Logger.java +++ b/src/main/java/usherbrooke/ift630/Logger.java @@ -3,14 +3,14 @@ package usherbrooke.ift630; public class Logger { private static Logger logger; - private static final String RED = "\u001B[31m"; - private static final String GREEN = "\u001B[32m"; - private static final String YELLOW = "\u001B[33m"; - private static final String BLUE = "\u001B[34m"; - private static final String PURPLE = "\u001B[35m"; - private static final String CYAN = "\u001B[36m"; - private static final String RESET = "\u001B[0m" ; - private static final String WHITE = "\u001B[0m"; + private static final String RED = "\u001B[31m"; + private static final String GREEN = "\u001B[32m"; + private static final String YELLOW = "\u001B[33m"; + private static final String BLUE = "\u001B[34m"; + private static final String PURPLE = "\u001B[35m"; + private static final String CYAN = "\u001B[36m"; + private static final String RESET = "\u001B[0m"; + private static final String WHITE = "\u001B[0m"; private String[] cols = { WHITE, @@ -22,30 +22,30 @@ public class Logger { CYAN, }; - private Logger() {} + private Logger() { + } public void printTime() { System.out.println(System.currentTimeMillis()); } public void printTime(String s) { - System.out.println(System.currentTimeMillis() + s); + System.out.println(System.currentTimeMillis() + s); } public void printTime(int c, String s) { - System.out.println(cols[c % cols.length] +System.currentTimeMillis() + s + RESET); + System.out.println(cols[c % cols.length] + System.currentTimeMillis() + s + RESET); } - public void print(int c, String s) { System.out.println(cols[c % cols.length] + s + RESET); } - - public static Logger getInstance() { - if(logger == null) { - logger = new Logger(); - } - - return logger; - } + + public static Logger getInstance() { + if (logger == null) { + logger = new Logger(); + } + + return logger; + } } diff --git a/src/main/java/usherbrooke/ift630/Stop.java b/src/main/java/usherbrooke/ift630/Stop.java index 3bd6feb..aa7c8de 100644 --- a/src/main/java/usherbrooke/ift630/Stop.java +++ b/src/main/java/usherbrooke/ift630/Stop.java @@ -20,13 +20,12 @@ public class Stop extends Thread { private Socket socket; private PrintWriter socketTx; - private void connectSocket() throws IOException { socket = new Socket("localhost", socketPort); socketTx = new PrintWriter(socket.getOutputStream(), true); } - // + // private void sendCurrentCapacity() throws IOException { connectSocket(); // prone to over estimation. Some passenger will take other lines. @@ -51,7 +50,8 @@ public class Stop extends Thread { Logger.getInstance().print(id, "\t".repeat(indent) + "[STOP] " + info.getBus(this).getNameBus() + " arrives in " + time + "s"); // else, catch - } catch (NullPointerException e) {} + } catch (NullPointerException e) { + } } catch (UnauthorizedException e) { // if unauth, requeue message. @@ -147,7 +147,7 @@ public class Stop extends Thread { } public void removePassenger(Passenger p) throws IOException { - if(passengers.remove(p)) { + if (passengers.remove(p)) { synchronized (p) { p.notify(); } diff --git a/src/main/java/usherbrooke/ift630/UnauthorizedException.java b/src/main/java/usherbrooke/ift630/UnauthorizedException.java index 80b4f72..e96979d 100644 --- a/src/main/java/usherbrooke/ift630/UnauthorizedException.java +++ b/src/main/java/usherbrooke/ift630/UnauthorizedException.java @@ -1,7 +1,8 @@ package usherbrooke.ift630; public class UnauthorizedException extends Exception { - public UnauthorizedException() {} + public UnauthorizedException() { + } public UnauthorizedException(String message) { super(message);