reformated everything.

it is not my fav formater, but at least its uniform, and its getting
late.
Good night!
This commit is contained in:
violette 2024-03-26 22:20:11 -04:00
parent 14c72c3f7a
commit abe0c16aa3
6 changed files with 52 additions and 49 deletions

View file

@ -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 {

View file

@ -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<Passenger>();
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<Passenger>();
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<Stop> getStops() {
return line.getStops();
}

View file

@ -1,7 +1,8 @@
package usherbrooke.ift630;
public class ExitException extends Exception {
ExitException() {}
ExitException() {
}
public ExitException(String message) {
super(message);

View file

@ -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();
}
public static Logger getInstance() {
if (logger == null) {
logger = new Logger();
}
return logger;
}
return logger;
}
}

View file

@ -20,7 +20,6 @@ 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);
@ -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();
}

View file

@ -1,7 +1,8 @@
package usherbrooke.ift630;
public class UnauthorizedException extends Exception {
public UnauthorizedException() {}
public UnauthorizedException() {
}
public UnauthorizedException(String message) {
super(message);