├── README.md ├── bin ├── hyperloop_vacuum_train │ ├── AboveGroundPipeLine.class │ ├── EscalatorMovingToHyperloopStation.class │ ├── HyperloopCollection$1.class │ ├── HyperloopCollection$10.class │ ├── HyperloopCollection$2.class │ ├── HyperloopCollection$3.class │ ├── HyperloopCollection$4.class │ ├── HyperloopCollection$5.class │ ├── HyperloopCollection$6.class │ ├── HyperloopCollection$7.class │ ├── HyperloopCollection$8.class │ ├── HyperloopCollection$9.class │ ├── HyperloopCollection.class │ ├── HyperloopPassenger.class │ ├── Main.class │ ├── Station.class │ ├── TravelCapsule.class │ ├── Turnstile.class │ ├── VacuumTrain.class │ └── VacuumTrainDriver.class └── log4j.properties ├── hyperloop.log └── src ├── hyperloop_vacuum_train ├── AboveGroundPipeLine.java ├── EscalatorMovingToHyperloopStation.java ├── HyperloopCollection.java ├── HyperloopPassenger.java ├── Main.java ├── Station.java ├── TravelCapsule.java ├── Turnstile.java ├── VacuumTrain.java └── VacuumTrainDriver.java └── log4j.properties /README.md: -------------------------------------------------------------------------------- 1 | # Functioning_OF_HYPERLOOP_VacuumTrain 2 | -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/AboveGroundPipeLine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/AboveGroundPipeLine.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/EscalatorMovingToHyperloopStation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/EscalatorMovingToHyperloopStation.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$1.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$10.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$10.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$2.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$3.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$4.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$5.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$6.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$7.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$7.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$8.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$8.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection$9.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection$9.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopCollection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopCollection.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/HyperloopPassenger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/HyperloopPassenger.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/Main.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/Station.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/Station.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/TravelCapsule.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/TravelCapsule.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/Turnstile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/Turnstile.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/VacuumTrain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/VacuumTrain.class -------------------------------------------------------------------------------- /bin/hyperloop_vacuum_train/VacuumTrainDriver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitRod/Functioning_OF_HYPERLOOP_VacuumTrain/04e8ff4364d8748cab5d4334d457a86a92301684/bin/hyperloop_vacuum_train/VacuumTrainDriver.class -------------------------------------------------------------------------------- /bin/log4j.properties: -------------------------------------------------------------------------------- 1 | # %F - file name (example Main.java)avoided unless execution speed is not an issue. 2 | # %M - method (avoided unless execution speed is not an issue.) 3 | # %L - line number in file (avoided unless execution speed is not an issue.) 4 | # %C - class name (avoided unless execution speed is not an issue.) 5 | # %p - priority name 6 | # %c - category name i.e. stdout, console, logfile and etc 7 | # %d - date write record 8 | # %d{} - date write record , options {hh:mm:ss} or {HH:MM:SS} or combination 9 | # %m - message 10 | # %n - end line \n working in any way 11 | # OFF< TRACE< DEBUG< INFO< WARN< ERROR< FATAL< ALL 12 | 13 | log4j.rootLogger=info, stdout, file 14 | 15 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 16 | log4j.appender.stdout.target=System.out 17 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.stdout.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 19 | 20 | log4j.appender.file=org.apache.log4j.FileAppender 21 | log4j.appender.file.file=hyperloop.log 22 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 23 | log4j.appender.file.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 24 | 25 | log4j.appender.debugfile=org.apache.log4j.FileAppender 26 | log4j.appender.debugfile.file=hyperloop-debug.log 27 | log4j.appender.debugfile.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.debugfile.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 29 | log4j.logger.com.my.app.somepackage=DEBUG, debugfile 30 | log4j.logger.com.my.app.somepackage.subpackage.ClassName=INFO -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/AboveGroundPipeLine.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class AboveGroundPipeLine { 6 | 7 | /** 8 | * class for pipeline of hyperloop 9 | */ 10 | 11 | String name; 12 | /** 13 | * list of vacuum trains in the pipeline 14 | */ 15 | 16 | LinkedList pipelineVacTrains; 17 | /** 18 | * list of stations in this pipeline 19 | */ 20 | LinkedList pipelineStations; 21 | 22 | public AboveGroundPipeLine(String name) { 23 | this.name = name; 24 | this.pipelineStations = new LinkedList(); 25 | } 26 | 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | public LinkedList getPipelineVacTrains() { 35 | return pipelineVacTrains; 36 | } 37 | public void setPipelineVacTrains(LinkedList pipelineVacTrains) { 38 | this.pipelineVacTrains = pipelineVacTrains; 39 | } 40 | public LinkedList getPipelineStations() { 41 | return pipelineStations; 42 | } 43 | public void setPipelineStations(LinkedList pipelineStations) { 44 | this.pipelineStations = pipelineStations; 45 | } 46 | 47 | 48 | @Override 49 | public String toString() { 50 | return "AboveGroundPipeLine [name=" + name + ", pipelineVacTrains=" + pipelineVacTrains + ", pipelineStations=" 51 | + pipelineStations + "]"; 52 | } 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/EscalatorMovingToHyperloopStation.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class EscalatorMovingToHyperloopStation { 6 | /** 7 | * Escalator name 8 | */ 9 | String name; 10 | 11 | public EscalatorMovingToHyperloopStation(String name) { 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "EscalatorMovingUpToHyperloopStation [name=" + name + "]"; 18 | } 19 | /** 20 | * Move number of passengers from one LinkedList to another 21 | * 22 | * @param numberOfPassengers 23 | * desired number of passengers to move 24 | * @param listFrom 25 | * source LinkedList<Passenger> 26 | * @param listTo 27 | * target LinkedList<Passenger> 28 | * @return recount number of passenger moved 29 | * @throws InterruptedException 30 | */ 31 | 32 | public int movePassengers(int numberOfPassengers, LinkedList listFrom, LinkedList listTo) 33 | throws InterruptedException { 34 | int counter = 0; 35 | 36 | for(int i = 0; i < numberOfPassengers; i++) { 37 | synchronized (listFrom) { 38 | 39 | if(!listFrom.isEmpty()) { 40 | HyperloopPassenger pass = listFrom.remove(); 41 | System.out.println(this.name + "===>>>[" + pass + "] "); 42 | counter++; 43 | listTo.add(pass); 44 | } 45 | } 46 | } 47 | if(counter > 0) 48 | System.out.println(""); 49 | return counter; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/HyperloopCollection.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | import java.util.HashMap; 6 | import java.util.HashSet; 7 | import java.util.Iterator; 8 | import java.util.LinkedHashSet; 9 | import java.util.LinkedList; 10 | import java.util.Map; 11 | import java.util.PriorityQueue; 12 | import java.util.Queue; 13 | import java.util.Random; 14 | import java.util.concurrent.BlockingQueue; 15 | import java.util.concurrent.CountDownLatch; 16 | import java.util.concurrent.LinkedBlockingQueue; 17 | import java.util.concurrent.PriorityBlockingQueue; 18 | 19 | 20 | import org.xmlpull.v1.XmlPullParserException; 21 | import org.xmlpull.v1.XmlPullParserFactory; 22 | import org.xmlpull.v1.XmlSerializer; 23 | 24 | public class HyperloopCollection { 25 | /** 26 | * Number of Capsules in depot 27 | */ 28 | public final static int CAPSULES_IN_DEPOT = 99; 29 | /** 30 | * Namespace for XML reports creation 31 | */ 32 | final String NAMESPACE = ""; 33 | /** 34 | * Depot for capsules 35 | */ 36 | 37 | LinkedList depot; 38 | 39 | HashSet vacTrains; 40 | /** 41 | * Three separate Pipelines of Hyperloop in The USA between different cities 42 | */ 43 | AboveGroundPipeLine LosAngelesLine, WashingtonLine, BostonLine; 44 | /** 45 | * Queue with Drivers to drive VacTrains 46 | */ 47 | BlockingQueue driverQueue; 48 | /** 49 | * Map to fast search remaining Hyperloop Passenger on the Station 50 | */ 51 | Map> passengersInStation; 52 | /** 53 | * Auxiliary random seed 54 | */ 55 | private Random rnd; 56 | 57 | /** 58 | * Comparator for priority queues 59 | */ 60 | private Comparator comparator; 61 | /** 62 | * Complete Hyperloop in USA 63 | */ 64 | ArrayList hyperloopUSA; 65 | /** 66 | * Auxiliary threads collection for join() them in main thread 67 | */ 68 | private ArrayList threads; 69 | 70 | /** 71 | *XML serializer 72 | */ 73 | XmlSerializer serializer; 74 | /** 75 | * Latch to start Passengers moving into the Capsule 76 | */ 77 | CountDownLatch startMovingToCapsuleLatch; 78 | /** 79 | * Latch to finish Passengers moving into the Capsule 80 | */ 81 | CountDownLatch finishMovingToCapsuleLatch; 82 | 83 | /*==========================================*/ 84 | 85 | /** 86 | * Constructing Hyperloop 87 | */ 88 | 89 | public HyperloopCollection() { 90 | this.rnd = new Random(); 91 | 92 | this.hyperloopUSA = new ArrayList<>(); 93 | this.depot = new LinkedList(); 94 | this.vacTrains = new LinkedHashSet(); 95 | this.passengersInStation = new HashMap<>(); 96 | this.threads = new ArrayList<>(); 97 | 98 | // creating XML serializer 99 | XmlPullParserFactory factory; 100 | try { 101 | factory = XmlPullParserFactory.newInstance(); 102 | this.serializer = factory.newSerializer(); 103 | } catch (XmlPullParserException e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | 108 | /** 109 | * Creating capsules for depot collection. Approximately 25% of leading capsules will be 110 | * created 111 | */ 112 | public void createCapsules() { 113 | for(int i = 0; i < CAPSULES_IN_DEPOT; i++) { 114 | TravelCapsule cps = new TravelCapsule("<> " + i, (rnd.nextInt(99) < 25)); 115 | depot.add(cps); 116 | } 117 | } 118 | /** 119 | * Creating vactrains from depot capsules usingf addCapsule method 120 | * Adds ready to go vacTrain to vactrain's collection 121 | */ 122 | 123 | public void createVacTrain() { 124 | // filling vactrains with capsules 125 | // maximum number of vactrains = size of depot / by the number of capsules 126 | // in the vactrain 127 | int maxVacTrainsNumber = depot.size() / VacuumTrain.MAX_NUMBER_OF_CAPSULES; 128 | 129 | for(int j = 0; j < maxVacTrainsNumber; j++) { 130 | VacuumTrain vactrain = new VacuumTrain("Vactrain " + j, "00" + j); 131 | while (!depot.isEmpty()) { 132 | vactrain.addCapsule(depot.poll()); 133 | if(vactrain.size == VacuumTrain.MAX_NUMBER_OF_CAPSULES) 134 | break; 135 | } 136 | if(vactrain.readyToGo) 137 | vacTrains.add(vactrain); 138 | } 139 | System.out.println(vacTrains); 140 | } 141 | /** 142 | * Creating three pipelines in the USA. Method adds them to HyperloopCollection 143 | */ 144 | public void createsPipeLines() { 145 | LosAngelesLine = new AboveGroundPipeLine("Los-Angeles --> San Francisco"); 146 | WashingtonLine = new AboveGroundPipeLine("Washington --> Boston"); 147 | BostonLine = new AboveGroundPipeLine("Boston --> New-York"); 148 | 149 | hyperloopUSA.add(LosAngelesLine); 150 | hyperloopUSA.add(WashingtonLine); 151 | hyperloopUSA.add(BostonLine); 152 | } 153 | 154 | /** 155 | * adding vactrains from vactrains collection to a pipeline vactrains 156 | */ 157 | public void createPipeLineVacTrains() { 158 | LosAngelesLine.setPipelineVacTrains(new LinkedList()); 159 | WashingtonLine.setPipelineVacTrains(new LinkedList()); 160 | BostonLine.setPipelineVacTrains(new LinkedList()); 161 | 162 | Iterator iter = vacTrains.iterator(); 163 | 164 | while (iter.hasNext()){ 165 | LosAngelesLine.pipelineVacTrains.add(iter.next()); 166 | if(iter.hasNext()) 167 | WashingtonLine.pipelineVacTrains.add(iter.next()); 168 | if(iter.hasNext()) 169 | BostonLine.pipelineVacTrains.add(iter.next()); 170 | } 171 | } 172 | 173 | /** 174 | * Prints a queue in right order. Using a copy of queue to poll 175 | * @param queue 176 | * - a queue (PriorityBlockingQueue or PriorityQueue) to print 177 | */ 178 | public void printPriorityQueue(Queue queue) { 179 | Queue temp; 180 | 181 | if(queue instanceof PriorityBlockingQueue) { 182 | temp = new PriorityBlockingQueue(10, comparator); 183 | } else { 184 | temp = new PriorityQueue(10, comparator); 185 | } 186 | for (Object e :queue) { 187 | temp.add((VacuumTrainDriver) e); 188 | } 189 | System.out.println("======================THE RESULT OF QUEUE====================="); 190 | while (!temp.isEmpty()) 191 | System.out.println(temp.poll()); 192 | } 193 | 194 | /** 195 | * Creates drivers and forms a driver queue from them. Comparator of queue 196 | * is based on drivers experience. Run all vacgetrains with available drivers in 197 | * different threads After all threads are finished - print a resulting 198 | * queue 199 | */ 200 | public void manageDriversQueue() { 201 | comparator = new Comparator() { 202 | 203 | @Override 204 | public int compare(VacuumTrainDriver o1, VacuumTrainDriver o2) { 205 | 206 | if (o1.getExperience() > o2.getExperience()) { 207 | return -1; 208 | } 209 | if(o1.getExperience() < o2.getExperience()) { 210 | return 1; 211 | } 212 | return 0; 213 | } 214 | }; 215 | 216 | driverQueue = new PriorityBlockingQueue(10, comparator); 217 | 218 | try { 219 | driverQueue.put(new VacuumTrainDriver("Valera", 9)); 220 | driverQueue.put(new VacuumTrainDriver("Volaev S.S", 30)); 221 | driverQueue.put(new VacuumTrainDriver("Stepanych", 55)); 222 | driverQueue.put(new VacuumTrainDriver("Trainee Petya", 5)); 223 | }catch (InterruptedException exep) { 224 | exep.printStackTrace(); 225 | } 226 | 227 | Iterator iter = vacTrains.iterator(); 228 | VacuumTrainDriver drv = null; 229 | 230 | getThreads().clear(); 231 | 232 | while (iter.hasNext()) { 233 | VacuumTrain vactrain = iter.next(); 234 | 235 | try { 236 | drv = driverQueue.take(); 237 | }catch (InterruptedException e) { 238 | e.printStackTrace(); 239 | } 240 | drv.setCurrentVacTrain(vactrain); 241 | doThreadDrive(drv); 242 | iter.remove(); 243 | } 244 | for(Thread curThread : getThreads()) { 245 | 246 | try { 247 | curThread.join(); 248 | }catch (InterruptedException e) { 249 | e.printStackTrace(); 250 | } 251 | } 252 | printPriorityQueue(driverQueue); 253 | } 254 | 255 | /** 256 | * Run vactrain with driver in a thread. Recount experience and after run ends - 257 | * return driver to the queue. 258 | * 259 | * @param drv 260 | */ 261 | public void doThreadDrive(VacuumTrainDriver drv) { 262 | Random rnd = new Random(); 263 | int miles = rnd.nextInt(50) + 1; 264 | 265 | Thread theThread = new Thread(new Runnable() { 266 | Random rnd = new Random(); 267 | 268 | @Override 269 | public void run() { 270 | System.out.println("VacTrain Driver " + drv.name + "[" + drv.experience + "] runs " 271 | + miles + " miles on the " + drv.currentVacTrain.name + " vactrain"); 272 | 273 | drv.recountExperience(miles); 274 | 275 | try { 276 | Thread.sleep(rnd.nextInt(5) * 1000); 277 | driverQueue.put(drv); 278 | } catch (InterruptedException e) { 279 | e.printStackTrace(); 280 | } 281 | 282 | } 283 | }); 284 | getThreads().add(theThread); 285 | theThread.start(); 286 | } 287 | 288 | /** 289 | * Adding stations to the pipelines(pipeline station collection) 290 | */ 291 | public void createPipeLineStations() { 292 | for(int i = 0; i < 10; i++) { 293 | LosAngelesLine.pipelineStations.add(new Station(LosAngelesLine.name + "Station " + i)); 294 | WashingtonLine.pipelineStations.add(new Station(WashingtonLine.name + "Station " + i)); 295 | BostonLine.pipelineStations.add(new Station(BostonLine.name + "Station " + i )); 296 | } 297 | } 298 | 299 | /** 300 | * Passengers from turnstile move to station via three escalators 301 | * 302 | * @throws InterruptedException 303 | */ 304 | public void passengersMoveEscalator() throws InterruptedException { 305 | 306 | //Constants for the number of passengers 307 | // appearance of passengers at the turnstile 308 | final int turnstileNew = 13; 309 | //passengers that leave station 310 | final int stationGone = 8; 311 | //passengers that move via escalator 312 | final int escalatorMoved = 4; 313 | 314 | // constants for threads to sleep 315 | final int turnstileSleep = 2000; 316 | final int stationSleep = 3000; 317 | final int escalatorSleep = 1000; 318 | 319 | // list of passengers at the station 320 | LinkedList stationPassengers = new LinkedList(); 321 | // you can change this list to list of the first station of first line 322 | // for instance 323 | // hyperloopUSA.get(0).pipelineStations.getFirst().getAwaitingPassengers(); 324 | 325 | EscalatorMovingToHyperloopStation escalator1 = new EscalatorMovingToHyperloopStation("ESCALATOR_1"); 326 | EscalatorMovingToHyperloopStation escalator2 = new EscalatorMovingToHyperloopStation("ESCALATOR_2"); 327 | EscalatorMovingToHyperloopStation escalator3 = new EscalatorMovingToHyperloopStation("ESCALATOR_3"); 328 | 329 | Turnstile turnstile = new Turnstile(); 330 | 331 | // Filling the turnstile with passengers 332 | Thread turnstileAdditionThread = new Thread(new Runnable() { 333 | Random rnd = new Random(); 334 | 335 | @Override 336 | public void run() { 337 | while (true) { 338 | turnstile.addPassengers(rnd.nextInt(turnstileNew)); 339 | 340 | try { 341 | Thread.sleep(turnstileSleep); 342 | } catch (InterruptedException e) { 343 | 344 | e.printStackTrace(); 345 | } 346 | System.out.println("At the Turnstile " + turnstile.turnstilePassengers.size()); 347 | System.out.println("Turnstile :" + turnstile.printPassengers()); 348 | } 349 | } 350 | }); 351 | turnstileAdditionThread.setName("The one who adds"); 352 | 353 | // Passengers leaving station in the vactrain 354 | Thread stationRemoverThread = new Thread (new Runnable() { 355 | Random rnd = new Random(); 356 | 357 | @Override 358 | public void run() { 359 | while (true) { 360 | try { 361 | System.out.println("At the station " + stationPassengers.size() + "; left in the vactrain" 362 | + removePassengers(rnd.nextInt(stationGone))); 363 | Thread.sleep(stationSleep); 364 | }catch (InterruptedException ex) { 365 | ex.printStackTrace(); 366 | } 367 | } 368 | 369 | } 370 | 371 | public int removePassengers(int numberOfPassengers) throws InterruptedException { 372 | int counter = 0; 373 | 374 | synchronized (stationPassengers) { 375 | for(int i = 0; i < numberOfPassengers; i++) { 376 | if(!stationPassengers.isEmpty()) { 377 | stationPassengers.remove(); 378 | counter++; 379 | } 380 | } 381 | } 382 | return counter; 383 | } 384 | 385 | }); 386 | 387 | stationRemoverThread.setName("The one who removes"); 388 | 389 | // Escalator 1 carries passengers from the turnstile to the station 390 | Thread escalator1Thread = new Thread (new Runnable() { 391 | Random rnd = new Random(); 392 | 393 | @Override 394 | public void run() { 395 | while(true) { 396 | try { 397 | Thread.sleep(escalatorSleep); 398 | System.out.println(" " + escalator1.name + " carried [" + escalator1.movePassengers( 399 | rnd.nextInt(escalatorMoved) + 1, turnstile.turnstilePassengers, stationPassengers) + "]"); 400 | }catch (InterruptedException ex) { 401 | ex.printStackTrace(); 402 | } 403 | } 404 | 405 | } 406 | 407 | }); 408 | 409 | escalator1Thread.setName("Escalator 1"); 410 | 411 | // Escalator 2 carries passengers from the turnstile to the station 412 | Thread escalator2Thread = new Thread (new Runnable() { 413 | Random rnd = new Random(); 414 | 415 | @Override 416 | public void run() { 417 | while(true) { 418 | try { 419 | Thread.sleep(escalatorSleep); 420 | System.out.println(" " + escalator2.name + " carried [" + escalator2.movePassengers( 421 | rnd.nextInt(escalatorMoved) + 1, turnstile.turnstilePassengers, stationPassengers) + "]"); 422 | }catch (InterruptedException ex) { 423 | ex.printStackTrace(); 424 | } 425 | } 426 | } 427 | 428 | }); 429 | 430 | escalator2Thread.setName("Escalator 2"); 431 | 432 | // Escalator 3 carries passengers from the turnstile to the station 433 | Thread escalator3Thread = new Thread (new Runnable() { 434 | Random rnd = new Random(); 435 | 436 | @Override 437 | public void run() { 438 | while(true) { 439 | try { 440 | Thread.sleep(escalatorSleep); 441 | System.out.println(" " + escalator3.name + " carried [" + escalator3.movePassengers( 442 | rnd.nextInt(escalatorMoved) + 1, turnstile.turnstilePassengers, stationPassengers) + "]"); 443 | }catch (InterruptedException ex) { 444 | ex.printStackTrace(); 445 | } 446 | } 447 | } 448 | 449 | }); 450 | 451 | escalator3Thread.setName("Escalator 3"); 452 | 453 | System.out.println("====================START==================="); 454 | 455 | //wainting for all threads 456 | turnstileAdditionThread.join(); 457 | stationRemoverThread.join(); 458 | escalator1Thread.join(); 459 | escalator2Thread.join(); 460 | escalator3Thread.join(); 461 | 462 | 463 | //we start the appearance and pick-up of passengers and wait a little bit 464 | turnstileAdditionThread.start(); 465 | stationRemoverThread.start(); 466 | Thread.sleep(2000 * 2); 467 | 468 | // we start the escalators 469 | escalator1Thread.start(); 470 | escalator2Thread.start(); 471 | escalator3Thread.start(); 472 | } 473 | 474 | 475 | /** 476 | * Creating passengers and running all vactrains through stations 477 | */ 478 | public void passengersInOutVacTrains() { 479 | getThreads().clear(); 480 | 481 | passengersEnterStations(); 482 | 483 | for(AboveGroundPipeLine pipeline : hyperloopUSA) { 484 | Iterator iterPipeline = pipeline.getPipelineVacTrains().iterator(); 485 | while (iterPipeline.hasNext()) { 486 | 487 | VacuumTrain vactrain = iterPipeline.next(); 488 | runVacTrainThread(pipeline, vactrain); 489 | } 490 | } 491 | } 492 | 493 | /** 494 | * Adding passengers to stations in thread. 495 | */ 496 | private void passengersEnterStations() { 497 | 498 | Thread theThread = new Thread(new Runnable() { 499 | Random rnd = new Random(); 500 | 501 | @Override 502 | public void run() { 503 | for(AboveGroundPipeLine pipeline : hyperloopUSA) { 504 | for(Station station : pipeline.pipelineStations) { 505 | for(int i = 0; i < rnd.nextInt(2345); i++) 506 | try { 507 | station.awaitingPassengers.put(new HyperloopPassenger("Hyperloop Passenger " + rnd.nextInt(1111))); 508 | Thread.sleep(1); 509 | }catch (InterruptedException e) { 510 | e.printStackTrace(); 511 | } 512 | Station.LOG 513 | .info(station.name + "s passengers are grown to " + station.awaitingPassengers.size()); 514 | } 515 | } 516 | 517 | } 518 | 519 | }); 520 | theThread.start(); 521 | getThreads().add(theThread); 522 | 523 | } 524 | /** 525 | * Runs vactrain through line. VacTrain stays at every station and let passengers 526 | * go out and in. VacTrain goes in separate thread. 527 | * 528 | * @param pipeline 529 | * - pipeline of Hyperloop 530 | * @param vactrain 531 | * - current vactrain 532 | */ 533 | private void runVacTrainThread(AboveGroundPipeLine pipeline, VacuumTrain vactrain) { 534 | 535 | Thread theThread = new Thread(new Runnable() { 536 | Random rnd = new Random(); 537 | int cntToOperate = 0, resultOper = 0; 538 | String reportToLog = ""; 539 | 540 | @Override 541 | public void run() { 542 | 543 | for(Station station : pipeline.pipelineStations) { 544 | 545 | cntToOperate = rnd.nextInt(45); 546 | 547 | VacuumTrain.LOG.info("<<--" + vactrain.name + "[" + vactrain.getPassengersCount() + "] :: " 548 | + station.name + "[" + station.awaitingPassengers.size() + "]"); 549 | reportToLog = ""; 550 | for(TravelCapsule cps : vactrain.capsules) { 551 | 552 | System.out.print(" " + cps.name + "[" + cps.passengers.size() + "] : "); 553 | reportToLog += " " + cps.name + "[" + cps.passengers.size() + "] : "; 554 | resultOper = 0; 555 | 556 | if (!cps.passengers.isEmpty()) { 557 | Iterator passIter = cps.passengers.iterator(); 558 | cntToOperate = rnd.nextInt(10); 559 | // a few passengers go out 560 | while(passIter.hasNext() && cntToOperate > 0) { 561 | 562 | cps.passengers.removeFirst(); 563 | cntToOperate--; 564 | resultOper++; 565 | } 566 | System.out.print(" " + resultOper + " out; "); 567 | reportToLog += " " + resultOper + " out; "; 568 | } 569 | 570 | // Passengers at the station board the capsules (everyone who can fit) 571 | 572 | resultOper = 0; 573 | 574 | while (cps.passengers.size() < TravelCapsule.MAX_CAPACITY & station.awaitingPassengers.size() > 0) { 575 | try { 576 | cps.passengers.add(station.awaitingPassengers.take()); 577 | } catch (InterruptedException e) { 578 | e.printStackTrace(); 579 | } 580 | resultOper++; 581 | } 582 | System.out.print("" + resultOper + " in; "); 583 | System.out.println(""); 584 | 585 | reportToLog += "" + resultOper + " in; "; 586 | } 587 | 588 | VacuumTrain.LOG.info(" " + vactrain.name + "[=====] " + reportToLog); 589 | 590 | VacuumTrain.LOG.info("->" + vactrain.name + "[" + vactrain.getPassengersCount() + "] :: " + station.name + "[" 591 | + station.awaitingPassengers.size() + "]"); 592 | // sleep 593 | try { 594 | Thread.sleep(300); 595 | } catch (InterruptedException e) { 596 | e.printStackTrace(); 597 | } 598 | } 599 | } 600 | 601 | }); 602 | theThread.start(); 603 | getThreads().add(theThread); 604 | } 605 | 606 | /** 607 | * Moving passengers into capsules 608 | */ 609 | public void movePassengersIntoCapsules() { 610 | 611 | // get the example of vactrain 612 | VacuumTrain testVacTrain = hyperloopUSA.get(0).pipelineVacTrains.get(0); 613 | Station testStation = hyperloopUSA.get(0).pipelineStations.get(0); 614 | 615 | for(int j = 0; j < 100; j++) { 616 | testStation.awaitingPassengers.add(new HyperloopPassenger("Pass " + j)); 617 | } 618 | 619 | startMovingToCapsuleLatch = new CountDownLatch(1); 620 | finishMovingToCapsuleLatch = new CountDownLatch(testVacTrain.capsules.size()); 621 | 622 | Random rnd = new Random(); 623 | 624 | for(TravelCapsule capsule : testVacTrain.capsules) { 625 | int passengersToMoveToCapsule = rnd.nextInt(testStation.awaitingPassengers.size() / 5); 626 | new Thread(new Runnable() { 627 | 628 | @Override 629 | public void run() { 630 | try { 631 | 632 | startMovingToCapsuleLatch.await(); 633 | System.out.println(capsule + " begins to fill ..."); 634 | for(int i = 0; i < passengersToMoveToCapsule; i++) { 635 | capsule.passengers.add(testStation.awaitingPassengers.poll()); 636 | System.out.println(capsule.getName() + "+"); 637 | Thread.sleep(100); 638 | } 639 | 640 | finishMovingToCapsuleLatch.countDown(); 641 | 642 | } catch (InterruptedException intExep) { 643 | intExep.printStackTrace(); 644 | } 645 | } 646 | }).start(); 647 | } 648 | 649 | System.out.println("Attention!!!... GO!"); 650 | startMovingToCapsuleLatch.countDown(); 651 | 652 | try { 653 | finishMovingToCapsuleLatch.await(); 654 | } catch (InterruptedException e) { 655 | e.printStackTrace(); 656 | } 657 | System.out.println(" Everyone got in the capsule"); 658 | System.out.println(testVacTrain); 659 | } 660 | 661 | 662 | 663 | 664 | public ArrayList getThreads(){ 665 | return threads; 666 | } 667 | 668 | } 669 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/HyperloopPassenger.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | public class HyperloopPassenger { 4 | /** 5 | * Name of passenger 6 | */ 7 | String name; 8 | /** 9 | * Internal counter for unique ID is assigned 10 | */ 11 | private static int idCounter = 0; 12 | /** 13 | * Passenger id 14 | */ 15 | private int id; 16 | 17 | public HyperloopPassenger(String name) { 18 | this.name = name; 19 | this.id = idCounter++; 20 | } 21 | 22 | public HyperloopPassenger() { 23 | this.id =idCounter++; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "HyperloopPassenger " + id ; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/Main.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.UnsupportedEncodingException; 6 | 7 | import org.xmlpull.v1.XmlPullParserException; 8 | 9 | public class Main { 10 | /** 11 | * Entering point of the project 12 | */ 13 | public static void main(String[] args) 14 | throws XmlPullParserException, IllegalArgumentException, IllegalStateException, FileNotFoundException, 15 | UnsupportedEncodingException, IOException, InterruptedException { 16 | 17 | 18 | HyperloopCollection hyperloop = new HyperloopCollection(); 19 | 20 | hyperloop.createCapsules(); 21 | System.out.println("__ __ ____ _____ ________ ____ ___ _____ ___"); 22 | hyperloop.createVacTrain(); 23 | System.out.println("___ _____ ______ _____ ___ ___ ______ __ ___"); 24 | hyperloop.createsPipeLines(); 25 | System.out.println("______ _______ ______ ________ ______ ___"); 26 | hyperloop.createPipeLineVacTrains(); 27 | System.out.println("_______ _______ ______ _________ ___ ____"); 28 | System.out.println(hyperloop.hyperloopUSA); 29 | System.out.println("____ ________ _____ _____ ________ _____"); 30 | 31 | 32 | hyperloop.manageDriversQueue(); 33 | System.out.println("____________________________________"); 34 | 35 | hyperloop.createPipeLineStations(); 36 | System.out.println(hyperloop.hyperloopUSA); 37 | System.out.println("____________________________________"); 38 | 39 | hyperloop.passengersMoveEscalator(); 40 | 41 | System.out.println("____________________________________"); 42 | 43 | hyperloop.passengersInOutVacTrains(); 44 | System.out.println("____________________________________"); 45 | 46 | hyperloop.movePassengersIntoCapsules(); 47 | 48 | System.out.println("____________________________________"); 49 | for(Thread curThread : hyperloop.getThreads()) { 50 | 51 | try { 52 | curThread.join(); 53 | } catch (InterruptedException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/Station.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | 4 | import java.util.concurrent.LinkedBlockingQueue; 5 | 6 | import org.apache.log4j.Logger; 7 | 8 | public class Station { 9 | 10 | public static final Logger LOG = Logger.getLogger(Station.class); 11 | final static int MAX_NUMBER_OF_PASSENGERS = 300; 12 | /** 13 | * Name of Station 14 | */ 15 | String name; 16 | /** 17 | * List of passengers on the station 18 | */ 19 | LinkedBlockingQueue awaitingPassengers; 20 | 21 | public Station(String name) { 22 | this.name = name; 23 | this.awaitingPassengers = new LinkedBlockingQueue(MAX_NUMBER_OF_PASSENGERS); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "Station [(" + name + "); await (" + awaitingPassengers.size() + ")]"; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public LinkedBlockingQueue getAwaitingPassengers() { 40 | return awaitingPassengers; 41 | } 42 | 43 | public void setAwaitingPassengers(LinkedBlockingQueue awaitingPassengers) { 44 | this.awaitingPassengers = awaitingPassengers; 45 | } 46 | 47 | 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/TravelCapsule.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class TravelCapsule { 6 | /** 7 | *Maximum capsule capacity 8 | */ 9 | public static final int MAX_CAPACITY = 30; 10 | 11 | /** 12 | * Checking whether the capsule is "leading" 13 | */ 14 | 15 | public boolean isLeadingCapsule; 16 | public String name; 17 | public String capsuleNumber; 18 | int capacity; 19 | 20 | /** 21 | * A list of passengers 22 | */ 23 | 24 | LinkedList passengers; 25 | 26 | public TravelCapsule(String name, boolean isLeadingCapsule) { 27 | this.name = name; 28 | this.isLeadingCapsule = isLeadingCapsule; 29 | capacity = 0; 30 | passengers = new LinkedList<>(); 31 | } 32 | 33 | public boolean isLeadingCapsule() { 34 | return isLeadingCapsule; 35 | } 36 | 37 | public void setLeadingCapsule(boolean isLeadingCapsule) { 38 | this.isLeadingCapsule = isLeadingCapsule; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getCapsuleNumber() { 50 | return capsuleNumber; 51 | } 52 | 53 | public void setCapsuleNumber(String capsuleNumber) { 54 | this.capsuleNumber = capsuleNumber; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "TravelCapsule [head=" + isLeadingCapsule + ", name=" + name + ", Num=" 60 | + capsuleNumber + "]"; 61 | } 62 | 63 | public int getCapacity() { 64 | return capacity; 65 | } 66 | 67 | public void setCapacity(int capacity) { 68 | this.capacity = capacity; 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/Turnstile.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.LinkedList; 4 | 5 | /** 6 | * Class that shows passengers at the turnstiles of lobby 7 | */ 8 | 9 | public class Turnstile { 10 | /** 11 | * Passengers at the turnstile 12 | */ 13 | LinkedList turnstilePassengers; 14 | 15 | 16 | public Turnstile() { 17 | turnstilePassengers = new LinkedList(); 18 | } 19 | 20 | public synchronized void addPassengers( int numberOfPassengers) { 21 | for(int i = 0; i < numberOfPassengers; i++) { 22 | turnstilePassengers.add(new HyperloopPassenger()); 23 | } 24 | notifyAll(); 25 | } 26 | 27 | public StringBuffer printPassengers() { 28 | StringBuffer sb = new StringBuffer(); 29 | synchronized (turnstilePassengers) { 30 | for(HyperloopPassenger pass : turnstilePassengers) 31 | sb.append("[" + pass + "] "); 32 | } 33 | return sb; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/VacuumTrain.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.apache.log4j.Logger; 6 | 7 | public class VacuumTrain { 8 | 9 | public static final Logger LOG = Logger.getLogger(VacuumTrain.class); 10 | 11 | /** 12 | * Maximum number of Capsules in a VacuumTrain 13 | */ 14 | 15 | public static final byte MAX_NUMBER_OF_CAPSULES = 3; 16 | 17 | public String name; 18 | public String number; 19 | public int size; 20 | 21 | /** 22 | * Checking whether vacuum train can go on its route 23 | */ 24 | 25 | public boolean readyToGo; 26 | 27 | /** 28 | * Hyperloop driver 29 | */ 30 | 31 | VacuumTrainDriver driver; 32 | public int passengersServed = 0; 33 | 34 | /** 35 | * Capsules of the vacuum Train 36 | */ 37 | 38 | public LinkedList capsules; 39 | 40 | public VacuumTrain(String name, String number) { 41 | this.name = name; 42 | this.number = number; 43 | this.size = 0; 44 | capsules = new LinkedList(); 45 | readyToGo = false; 46 | } 47 | 48 | /** 49 | * Checking whether the first capsule is a head 50 | * @return true if it is so 51 | */ 52 | public boolean hasLeadingCapsule() { 53 | return((capsules.size() > 0) && (capsules.getFirst().isLeadingCapsule)); 54 | } 55 | 56 | /** 57 | * Checking whether the last capsule is a head 58 | * @return true if it is so 59 | */ 60 | public boolean hasTrailerCapsule() { 61 | return ((capsules.size() > 0) && (capsules.getLast().isLeadingCapsule)); 62 | } 63 | 64 | 65 | 66 | 67 | public void addCapsule(TravelCapsule cps) { 68 | if(this.size < MAX_NUMBER_OF_CAPSULES) { 69 | if(cps.isLeadingCapsule & !hasLeadingCapsule()) 70 | capsules.addFirst(cps); 71 | else { 72 | if(cps.isLeadingCapsule & !hasTrailerCapsule()) 73 | capsules.add(cps); 74 | else { 75 | if(!hasLeadingCapsule() || !hasTrailerCapsule()) 76 | capsules.add(cps); 77 | else 78 | capsules.add(1, cps); 79 | } 80 | } 81 | 82 | renumberCapsules(); 83 | this.size = this.capsules.size(); 84 | readyToGo = hasLeadingCapsule() & hasTrailerCapsule() & (size == MAX_NUMBER_OF_CAPSULES); 85 | 86 | } else 87 | System.out.println(" There should NOT be added more capsules"); 88 | } 89 | 90 | public void renumberCapsules() { 91 | for(TravelCapsule cps :capsules) { 92 | cps.setCapsuleNumber(this.number + "" + capsules.indexOf(cps)); 93 | } 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | return "VacuumTrain [name=" + name + ", readyToGo=" + readyToGo + ", num=" + number + ", size=" + size + 99 | ", capsules=" + capsules + ", driver=" + driver + "]"; 100 | } 101 | 102 | public VacuumTrainDriver getDriver() { 103 | return driver; 104 | } 105 | 106 | public void setDriver(VacuumTrainDriver driver) { 107 | this.driver = driver; 108 | } 109 | 110 | 111 | public int getPassengersCount() { 112 | int cnt = 0; 113 | for(TravelCapsule cps : this.capsules) 114 | cnt += cps.passengers.size(); 115 | return cnt; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/hyperloop_vacuum_train/VacuumTrainDriver.java: -------------------------------------------------------------------------------- 1 | package hyperloop_vacuum_train; 2 | 3 | import java.util.Random; 4 | 5 | public class VacuumTrainDriver { 6 | /** 7 | * Name of a driver 8 | */ 9 | String name; 10 | /** 11 | * Current experience of driver 12 | */ 13 | int experience; 14 | /** 15 | * Current VacTrain 16 | */ 17 | VacuumTrain currentVacTrain; 18 | 19 | public VacuumTrainDriver(String name, int experience) { 20 | this.name = name; 21 | this.experience = experience; 22 | } 23 | 24 | public void recountExperience(int miles) { 25 | Random rnd = new Random(); 26 | this.experience +=rnd.nextInt(miles); 27 | } 28 | 29 | /** 30 | * Travel and recounting experience 31 | */ 32 | 33 | public void doDrive() { 34 | recountExperience(70); 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "VacuumTrainDriver [name=" + name + ", experience=" + experience + "]"; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public int getExperience() { 51 | return experience; 52 | } 53 | 54 | public void setExperience(int experience) { 55 | this.experience = experience; 56 | } 57 | 58 | public VacuumTrain getCurrentVacTrain() { 59 | return currentVacTrain; 60 | } 61 | 62 | public void setCurrentVacTrain(VacuumTrain currentVacTrain) { 63 | this.currentVacTrain = currentVacTrain; 64 | currentVacTrain.setDriver(this); 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/log4j.properties: -------------------------------------------------------------------------------- 1 | # %F - file name (example Main.java)avoided unless execution speed is not an issue. 2 | # %M - method (avoided unless execution speed is not an issue.) 3 | # %L - line number in file (avoided unless execution speed is not an issue.) 4 | # %C - class name (avoided unless execution speed is not an issue.) 5 | # %p - priority name 6 | # %c - category name i.e. stdout, console, logfile and etc 7 | # %d - date write record 8 | # %d{} - date write record , options {hh:mm:ss} or {HH:MM:SS} or combination 9 | # %m - message 10 | # %n - end line \n working in any way 11 | # OFF< TRACE< DEBUG< INFO< WARN< ERROR< FATAL< ALL 12 | 13 | log4j.rootLogger=info, stdout, file 14 | 15 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 16 | log4j.appender.stdout.target=System.out 17 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.stdout.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 19 | 20 | log4j.appender.file=org.apache.log4j.FileAppender 21 | log4j.appender.file.file=hyperloop.log 22 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 23 | log4j.appender.file.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 24 | 25 | log4j.appender.debugfile=org.apache.log4j.FileAppender 26 | log4j.appender.debugfile.file=hyperloop-debug.log 27 | log4j.appender.debugfile.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.debugfile.layout.conversionPattern=[%d{hh:mm:ss}][%5p] %t %c{1}:%M:%L - %m%n 29 | log4j.logger.com.my.app.somepackage=DEBUG, debugfile 30 | log4j.logger.com.my.app.somepackage.subpackage.ClassName=INFO --------------------------------------------------------------------------------