<repo_name>trestikp/pt_semestralka<file_sep>/src/functions/PathFinder.java
package functions;
 import java.util.ArrayList;

import objects.Path;

/**
 * Class finding paths of the graph
 * @author <NAME> a <NAME>
 */
public class PathFinder {
 	
	private static Path[][] distancePaths;
	private static Path[][] timePaths;


	/**
	 * The main method finding the paths
	 * @param pat distance matrix
	 * @param timepat time matrix
	 */
	public static void pathFinding(short[][] pat, short[][] timepat) {
		
		/*for(int y=0;y<pat.length;y++) {
			for(int x=0;x<pat.length;x++) {
				if(pat[y][x]==-1)
				pat[y][x]=Integer.MAX_VALUE;
			}
		}*/
		Thread threadPathFinder = new Thread(new Runnable() {
			@Override
			public void run() {
					try {
	
						System.out.println("Time paths");
						PathFinder.timePaths=pathFinding(timepat);
						System.out.println("Time Paths done");
					}
				   catch (Exception ex) {
					   ex.printStackTrace();
				}
			}
		});
		threadPathFinder.start();
		
		System.out.println("Distance paths");
		PathFinder.distancePaths=pathFinding(pat);
		System.out.println("Distance Paths done");
		try {
			while(threadPathFinder.isAlive()) {
				
					Thread.sleep(50);
				
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	
	private static Path[][] pathFinding(short[][] paths ) {
		 final int size= paths.length;
		
		 Path[][] result= PathsInitialization(paths);
		
		
		////////////////////////////////////////////////////////////
		//cesty z uzlu j
		for(short j=0;j<size;j++) {
			boolean[] done= new boolean[size];
			for(int x=0;x<j;x++) {
				done[x]=true;
			}
			//okopirovani (pravidlo symetrie)  --funguje
			for(short x=0;x<j;x++) {
				if(result[x][j]!=null) {
					if(result[j][x]==null||
					result[j][x].getValue()>result[x][j].getValue()) {
					result[j][x]=new Path(result[x][j]);
					}
				}
			}
			//cesty z vrcholu actualPoint (i prvku uz je hotovo) do ostatnich vrcholu --
			dijkstraAlgorithm(result, done, j, paths);
		}
		
		
		return result;
	}
	
	
	private static Path[][] PathsInitialization(short[][] paths) {
		final int size= paths.length;
		Path[][] result= new Path[size][size];
		
		
		for(short y=0;y<size;y++) {
			//okopirovani (<NAME>)
			for(short x=0;x<y;x++) {
				if(result[x][y]!=null) {
					//reversed Path
					result[y][x]=new Path(result[x][y]);
				}
			}
			// z bodu x do x dojdu za 0 kroku
			result[y][y]=new Path(y,y,(short)0);
			// vytvareni novych cest
			for(short x=(short) (y+1);x<size;x++) {
				if(paths[y][x]!=0) {
					result[y][x] = new Path(y, x, paths[y][x]);
				}
			}
		}
		return result;
		
		
	}
	
	private static void dijkstraAlgorithm(Path[][] result, boolean[] done, short j, short[][] paths) {
		final int size= result.length;
		int actualPoint=j;
		for(short i=j;i<size;i++){
			
			//TODO
			//hledani nejmensiho ohodnoceni pro dalsi krok
			short minimal=0;
			for(short index=j; index<size;index++) {
				if(result[j][index]!=null && !done[index]) {
					if(minimal==0 || minimal>result[j][index].getValue()) {
						minimal=result[j][index].getValue();
						actualPoint=index;
					}
				}
			}
			done[actualPoint]=true;
			
			// uz zname nejkratsi cestu 
			// ted porovnat jestli neexistuje kratsi cesta k x prvku
			for(short x=0;x<size;x++) {
				if(!done[x] && paths[actualPoint][x]!=0) {
					if(result[j][x]==null|| //(result[j][x].getValue()>0 &&
							(result[j][actualPoint].getValue()+paths[actualPoint][x])
							<result[j][x].getValue()) {
						Path cest=result[j][actualPoint];
						result[j][x]=new Path(new ArrayList<Short>(cest.getNodeIDs()),cest.getValue());
						result[j][x].addNode(x, paths[actualPoint][x]);
					}
				}
			}	
		}
	}

	/**
	 * Distance paths getter
	 * @return distance paths matrix
	 */
 	public static Path[][] getDistancePaths() {
		return distancePaths;
	}

	/**
	 * Time paths getter
	 * @return time paths matrix
	 */
 	public static Path[][] getTimePaths() {
		return timePaths;
	}
 	
	
	
	
	
}<file_sep>/src/objects/HQ.java
package objects;

import java.awt.geom.Point2D;

/**
 * 
 * Class representing the HQ
 * @author <NAME> and <NAME>
 */
public class HQ extends AMansion{

	/**
	 * HQ is the main building of our company
	 * @param position of the HQ
	 */
	public HQ(Point2D position) {
		super(position);
	}

	/**
	 * Method returns text info about HQ
	 * @return text
	 */
	public String HQInfo(){
		String res = "";
		res += "iD: 0\n";
		res += "Name: HQ\n";
		res += "Location: [" + position.getX() + "," + position.getY() +"]";
		return res;
	}
}
<file_sep>/src/simulation/Simulation.java
package simulation;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import delivery.Order;
import delivery.Truck;
import functions.FileIO;
import objects.AMansion;
import objects.Mansion;
import objects.Path;
import objects.Pomocna;

public class Simulation {

	public static final int MINUTES_IN_DAY = 1440;
	public static final int START_OF_ORDERING_IN_MIN = 360;
	public static final int END_OF_ORDERING_IN_MIN = 1080;
	
	private int numDay=1;
	
	
	
	
	private static final Random RAND= new Random();
	
	/** List of mansions */
	public List<AMansion> nodes;
	private int actualTimeinMin=330;
	/**
	 * Pocet kolikrat uz bylo za den provedeno objednavani
	 */
	private int orderingTimesDone;
	/**
	 * Kdy naposled probihalo generovani objednavani
	 */
	private int lastCheckInMin;
	
	/**
	 * distance/time path preference false=time true=distance
	 */
	public boolean distanceXorTime=false;
	
	private  final Pomocna matrix;
	/** Distance paths */
	public  final Path[][] distancePath;
	/** Time paths */
	public final Path[][] timePathInMin;
	
	private LinkedList<Order>[] ordersToDo=new LinkedList[6];
	
	
	//atributy vlakna
	 private boolean stoped;
	 private boolean endSim = false;
	
	
	//exponencialni rozdeleni
		private static final double LAMBDA=300;

	/**
	 * Constructor creating simulation
 	 * @param g list of mansions
	 * @param matrix matrix carrier
	 * @param distancePaths distance paths
	 * @param timePaths time paths
	 */
	public Simulation(List<AMansion> g,Pomocna matrix,Path[][] distancePaths, Path[][] timePaths) {
		this.matrix=matrix;
		this.distancePath=distancePaths;
		this.timePathInMin=timePaths;
		
		this.nodes=g;
		for(int i=0;i<ordersToDo.length;i++) {
			ordersToDo[i]=new LinkedList<Order>();
		}
	}
	 

	/**
	 * spusti simulaci
	 * @param dobaCekani doba trvani jedne minuty simulace v ms
	 */
	public void runSimulation(int dobaCekani) {
		File f = new File("statistics.xml");
		f.delete();
		FileIO.startStatistics(null);
		Thread vlaknoSimulace = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					
					
					stoped = false;
					while(true) {
						
						if (endSim) {
							return;
						}
						if (!stoped) {
							simulationStep();
							Thread.sleep(dobaCekani);
						}
						System.out.print("");
					}
					}
				   catch (Exception ex) {
					   ex.printStackTrace();
				}
			}
		});
		vlaknoSimulace.start();
	}

	/**
	 * Ends simulation
	 */
	public void endSimulation() {
		endSim=true;
		Truck.addToTotalStats();
		FileIO.writeStatistics(Truck.launchableTrucks, Truck.trucksOnRoad, this, null);
		FileIO.wholeSimAllTruckStats(null);
		FileIO.endStatistics(null);
	}
	/**
	 * pozastavi simulaci
	 */
	public void pauseSim() {
		stoped = true;
	}
	
	/**
	 * znovu spusti pozastavenou simulaci
	 */
	public void resumeSim() {
		stoped = false;
	}


	private void simulationStep() {
		if(actualTimeinMin>=MINUTES_IN_DAY) {
			nextDay();
		}
		

		if(actualTimeinMin-lastCheckInMin>=5) {
			orderTime();
			//What is going on the road drivers?
			if(!Truck.trucksOnRoad.isEmpty()) {
				Truck.checkStateOnRoad(actualTimeinMin);
			}
		}
		actualTimeinMin++;
		
		
	
		
	}
		
	
	private void orderTime() {
	///je mezi 6. hodinou rann� a 6. ve�ern� (�as objedn�vek)
	
		//kazdych 5 minut
			
			lastCheckInMin=actualTimeinMin;
			System.out.print("TIME= "+minToHour(actualTimeinMin));
			
			if(actualTimeinMin>=START_OF_ORDERING_IN_MIN&&actualTimeinMin< Mansion.DEFAULT_END_OF_OPENING_IN_MIN) {
				
					if(actualTimeinMin<END_OF_ORDERING_IN_MIN) {
						generateRandomOrders();
						orderingTimesDone++;
					}
					System.out.println("Number of orders: "+getCountOfOrders());
					splitOrders();
					launchAllTrucks();
				}

				
				
			
			

			
	}
	
	private void generateRandomOrders() {
		double chance= (((1/LAMBDA)*Math.exp(-orderingTimesDone/LAMBDA)))*1000;
		for(int i = 1; i < matrix.mansionQuantity(); i++) {
			if(((Mansion)nodes.get(i)).canOrder()){
				int chancePoint = RAND.nextInt(1000);
				if(chancePoint<=chance) {
					Mansion orderingMansion = (Mansion) nodes.get(i);
					if(orderingMansion.getCanOrderNumber() < 1){
						return;
					}
					int	amount = getRandomAmouth(orderingMansion.getCanOrderNumber());
							/*Math.min(getRandomAmouth(orderingMansion.getCanOrderNumber()),orderingMansion.getCanOrderNumber());*/
					ordersToDo[amount-1].add(new Order(orderingMansion,amount, false));
					orderingMansion.orderCreated(amount);
			}
			}
		}
	}
	
	private int getCountOfOrders() {
		int result = 0;
		for(int i=0; i < ordersToDo.length; i++) {
			result+=ordersToDo[i].size();
		}
		return result;
	}
	
	private int getRandomAmouth(int size) {
		int chance=25;
		for(int i=1, addChance=25; i < size; i++, addChance-=5) {
			chance+=addChance;
		}
		int result= RAND.nextInt(chance);
		
		if(result < 26) {
			return 1;
		}
		else if(result < 51) {
			return 2;
		}
		else if(result < 71) {
			return 3;
		}
		else if(result < 86) {
			return 4;
		}
		else if(result < 96) {
			return 5;
		}
		else {
			return 6;
		}
		
	}
	/**
	 * method serves to inform others about actual day of the simulation
	 * @return actual day of sim
	 */
	public int getActualDay() {
		return numDay;
	}
	
	
	
	private void launchAllTrucks() {
		for(int i = 0; i<Truck.launchableTrucks.size(); i++) {
			
			if(Truck.launchableTrucks.peek().hasOrder()) {
				Truck.launchableTrucks.peek().sendOnRoad(actualTimeinMin);
			}
			else {
				break;
			}
		}
	}

	private void splitOrders() throws IndexOutOfBoundsException  {
		
		for(int index=5;index>=0;index--) {
			
			int loadingTime = (index+1)*Truck.UNLOAD_TIME_IN_MIN;
			int aproxSetOnRoad= actualTimeinMin+loadingTime;
			
			if(ordersToDo[index].isEmpty()) {
				continue;
			}
			for(int ind=ordersToDo[index].size()-1;ind>=0;ind--) {
			
				if(ind >= ordersToDo[index].size()) {
					ind = ordersToDo[index].size()-1;
				}
				Mansion o = ordersToDo[index].get(ind).getSubscriber();
				int aproxTime= aproxSetOnRoad + timePathInMin[0][o.iD].getValue();
				
				if((aproxTime) < (o.openingTimeInMin+Mansion.OPENED_TIME_IN_MIN)
						&& o.openingTimeInMin <= aproxTime) {
					prepareOrdersList(index, ind, aproxTime, loadingTime, o);
					if(ordersToDo[index].isEmpty()) {
						break;
					}
				}
			}

			
			
		}
	}
	
	private void prepareOrdersList(int index, int ind, int aproxTime, int loadingTime, Mansion o) {
		Order o1 = ordersToDo[index].get(ind);
		assignOrderToTruck(o1);
		//after unloading package
		int aproxTimeWhenDone = aproxTime+loadingTime;
		o1.setProbableTime(aproxTime);
		switch(index) {
			case 5: break;
			case 4:
				additionalOrders(1, o.iD,aproxTimeWhenDone);
				break;
			case 3:
				additionalOrders(2, o.iD,aproxTimeWhenDone);
				break;
			case 2:
				additionalOrders(3, o.iD,aproxTimeWhenDone);
				break;
			case 1:
				additionalOrders(4, o.iD,aproxTimeWhenDone);
				break;
			case 0:
				additionalOrders(5, o.iD,aproxTimeWhenDone);
				break;
			default:
				System.out.println("Tu se nikdy nedostaneme");
				return;
		}
	}
	
	private void additionalOrders(int neededSize, int pointID, int aproxtime) {
		int orderIndex=neededSize-1;
		while(orderIndex >= 0 && neededSize > 0) {
			//bs to look for bigger orders if size is smaller 
			if(orderIndex >= neededSize) {
				orderIndex=neededSize-1;
			}
			//No orders left, lets try "smaller" orders
			if(ordersToDo[orderIndex].size() == 0) {
				orderIndex--;
				continue;
			}
		Order o=null;
			if(distanceXorTime) {
				o=findClosePointWithOrder(pointID, orderIndex,distancePath, aproxtime);
			}
			else{
				o=findClosePointWithOrder(pointID, orderIndex,timePathInMin, aproxtime);
			}
		if(o == null) {
			orderIndex--;
			continue;
		}else {
			aproxtime+= (orderIndex+1)*Truck.UNLOAD_TIME_IN_MIN*2+timePathInMin[pointID][o.getSubscriber().iD].getValue() ;
			o.setProbableTime(aproxtime);
			pointID=o.getSubscriber().iD;
			assignOrderToTruck(o);
			neededSize-=(orderIndex+1);
		}
		

		}
	}
	
	
	private Order findClosePointWithOrder(int startPoint,int orderSize,Path[][] path, int aproxtime) {

		int velikost=ordersToDo[orderSize].size();
		int minValue= Integer.MAX_VALUE;
		Order result=null;
		aproxtime+=Truck.UNLOAD_TIME_IN_MIN*(orderSize+1);
		
		for(int i=velikost-1;i>=0;i--) {
			Mansion m=ordersToDo[orderSize].get(i).getSubscriber();
				if(result==null|| path[startPoint][m.iD] != null &&
						path[startPoint][m.iD].getValue()<minValue &&
						(aproxtime) < (m.openingTimeInMin+Mansion.OPENED_TIME_IN_MIN)
								&& m.openingTimeInMin >= aproxtime) {
						result=ordersToDo[orderSize].get(i);
					
				}
		}
		return result;
		
	}
	
	private void assignOrderToTruck(Order o) {
		if(o==null) {
			return;
		}
		
		//System.out.println("assigning orders");
		if(Truck.launchableTrucks.isEmpty()) {
			Truck t=new Truck();
			try {
				t.addOrder(o);
			} catch (Exception e) {
				e.printStackTrace();
			}
			ordersToDo[o.getAmount()-1].remove(o);

		}
		
		else {
			while(!Truck.launchableTrucks.isEmpty()) {
				Truck t=Truck.launchableTrucks.peek();
				if(t.canLoad(o.getAmount())) {
					try {
						t.addOrder(o);
					} catch (Exception e) {
						e.printStackTrace();
					}
					ordersToDo[o.getAmount()-1].remove(o);
					return;
				}else {
					t.sendOnRoad(actualTimeinMin);
				}
				
			}
			if(Truck.launchableTrucks.isEmpty()) {
				assignOrderToTruck(o);
			}
		}
	}
	

	private void nextDay() {
		FileIO.writeStatistics(Truck.launchableTrucks, Truck.trucksOnRoad, this, null);
		Mansion.nextDay(nodes);
		Truck.nextDay();
		actualTimeinMin=0;
		lastCheckInMin=0;
		
		Order.numberOfAllOrders =0;
		numDay++;
		System.out.println("Day "+numDay);
		
	}

	//////// Other accesories

	/**
	 * Method for creating manual order
	 * @param size number of pallets
	 * @param mansion subscriber
	 */
	public void manualOrder(int size, int mansion) {
		ordersToDo[size-1].add(new Order((Mansion)nodes.get(mansion),size, true));
		System.out.println("CREATED MANUAL ORDER");
	}
	
	
	/**
	 * Returns day of the simulation
	 * @return number of day
	 */
	public int getDay(){
		return numDay;
	}

	private String minToHour(int min){
		String res = "";
		if(min > 60){
			int hours = min/60;
			int minutes = min%60;
			if(hours < 10){
				res += "0" + hours + ":";
			} else {
				res += hours + ":";
			}
			if(minutes < 10){
				res += "0" + minutes + "\n";
			} else {
				res += minutes + "\n";
			}
		} else {
			if(min < 10){
				res = /*min + " min.\n";*/"0:0" + min + "\n";
			} else {
				res = /*min + " min.\n";*/"0:" + min + "\n";
			}
		}
		return res;
	}
	
}
<file_sep>/src/graphics/GuiController.java
package graphics;

import delivery.Truck;
import functions.FileIO;
import functions.PathFinder;
import generation.Generator;
import generation.PathGenerator;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;

import javafx.scene.control.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.util.StringConverter;
import objects.AMansion;
import objects.HQ;
import objects.Mansion;
import objects.Pomocna;
import simulation.Simulation;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

/**
 * Class controlling components of GUI
 * @author <NAME> and <NAME>
 */
public class GuiController {
    /** Simulation speed in [ms]. Default value = 20ms */
    private int simulation_speed;
    /** Logical variables determining if data were imported or generated */
    private boolean mansionsImported = false, matrixesImported = false, dataGenerated = false;

    /** TextArea to which console is redirected */
    @FXML
    private TextArea consoleLog;

    /** TextArea to which info about truck/ mansion is displayed */
    @FXML
    private TextArea infoLog;

    /** TextField where number of mansions to generate is inputted */
    @FXML
    private TextField manCount;

    /** TextField where speed of simulation is inputted */
    @FXML
    private TextField simSpeed;

    /** Button that starts the simulation */
    @FXML
    private Button startBtn;

    /** Button that pauses the simulation */
    @FXML
    private Button pauseBtn;

    /** Button that stops the simulation */
    @FXML
    private Button stopBtn;

    /** Button that resumes the simulation */
    @FXML
    private Button resumeBtn;

    /** ComboBox to choose truck for displaying information */
    @FXML
    private ComboBox<Truck> truckCombo;

    /** ComboBox to choose mansion for displaying information */
    @FXML
    private ComboBox<AMansion> manCombo;

    @FXML
    private Button orderBtn;

    /**
     * Empty constructor
     */
    public GuiController(){
        //prazdny constructor
    }

    /**
     * Method for initialization
     */
    @FXML
    private void initialize(){
        stopBtn.setDisable(true);
        pauseBtn.setDisable(true);
        resumeBtn.setDisable(true);
        orderBtn.setDisable(true);

        TextAreaConsole tac = new TextAreaConsole(consoleLog);
        tac.start();
    }

    /**
     * Action of start button
     */
    @FXML
    public void startAction(){
        if(!dataGenerated){
            if(matrixesImported && mansionsImported){
                System.out.println("\n--------------Start of finding Paths--------------\n");
                GUI.g = new Generator(GUI.mansions);
                GUI.g.generateOpeningTimesInMin();
                PathFinder.pathFinding(GUI.distanceMatrix, GUI.timeMatrix);
                System.out.println("\n--------------End of finding Paths--------------\n");
                GUI.sim = new Simulation(GUI.mansions,new Pomocna(GUI.distanceMatrix,GUI.timeMatrix),
                        PathFinder.getDistancePaths(),PathFinder.getTimePaths());
            } else {
                if(mansionsImported){
                    GUI.g = new Generator(GUI.mansions);
                    GUI.g.generateOpeningTimesInMin();
                    GUI.p = new PathGenerator(GUI.mansions);
                    System.out.println("Matrixes not imported! Starting generating new roads.");
                    long start = System.nanoTime();
                    GUI.p.generatePaths();
                    long end = System.nanoTime();
                    System.out.println("\n Finished generating roads in: " + (end/1000000 -start/1000000) + "ms\n");
                    GUI.distanceMatrix = GUI.p.getDistanceMatrix();
                    GUI.timeMatrix = GUI.p.getTimeMatrix();
                    System.out.println("\n--------------Start of generating Paths--------------\n");
                    PathFinder.pathFinding(GUI.distanceMatrix, GUI.timeMatrix);
                    System.out.println("\n--------------End of generating Paths--------------\n");
                    GUI.sim = new Simulation(GUI.mansions,new Pomocna(GUI.distanceMatrix,GUI.timeMatrix),
                            PathFinder.getDistancePaths(),PathFinder.getTimePaths());
                } else {
                    if(matrixesImported){
                        System.out.println("Matrixes imported, but mansions are missing, please import mansions or" +
                                " generate new mansions (this will generate new roads).");
                        return;
                    } else {
                        System.out.println("Don't have any data. Please import or generate data.");
                        return;
                    }
                }
            }
        }

        if(!(simSpeed.getText().equals(""))){
            try{
                int speed = Integer.parseInt(simSpeed.getText());
                if(speed < 15){
                    System.out.println("Speed of the simulation must be 15 or more ms!");
                    return;
                } else {
                    simulation_speed = Integer.parseInt(simSpeed.getText());
                }
            } catch (NumberFormatException e){
                System.out.println("Not a valid number! Please enter a whole number.");
                return;
            }

            //System.out.println("CAS SIM: " + simulation_speed);
        } else {
            simulation_speed = 20;
        }
            //setManComboBox();
            Thread sim = new Thread(() -> {
                GUI.sim.runSimulation(simulation_speed);
                try{
                    Thread.sleep(2);
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
            });
            sim.start();
            while (sim.isAlive()){
                setManComboBox();
            }

        stopBtn.setDisable(false);
        pauseBtn.setDisable(false);
        startBtn.setDisable(true);
    }

    /**
     * Action of resume button
     */
    @FXML
    public void resumeAction() {
        GUI.sim.resumeSim();
        pauseBtn.setDisable(false);
        stopBtn.setDisable(false);
        resumeBtn.setDisable(true);
        orderBtn.setDisable(true);
    }

    /**
     * Action of stop button
     */
    @FXML
    public void stopAction() {
        GUI.sim.endSimulation();
        setTruckComboBox();
        setManComboBox();
        System.out.println("\n--------------End of simulation--------------\n");
        resumeBtn.setDisable(true);
        pauseBtn.setDisable(true);
        stopBtn.setDisable(true);
        orderBtn.setDisable(true);
        dataInfoReset();
    }

    /**
     * Action of pause button
     */
    @FXML
    public void pauseAction() {
        GUI.sim.pauseSim();
        setTruckComboBox();
        setManComboBox();
        resumeBtn.setDisable(false);
        startBtn.setDisable(true);
        stopBtn.setDisable(false);
        pauseBtn.setDisable(true);
        orderBtn.setDisable(false);
    }

    /**
     * Action of generate button
     */
    @FXML
    public void generate(){
        GUI.dataReset();
        startBtn.setDisable(false);
        truckCombo.setValue(null);
        manCombo.setValue(null);
        infoLog.setText("");
        if(manCount.getText().equals("")){
            Thread gen = new Thread(() -> GUI.runGeneration(2000));
            gen.start();
            //GUI.runGeneration(2000);
        } else {
            try{
                int genCount = Integer.parseInt(manCount.getText());
                if(/*Integer.parseInt(manCount.getText())*/genCount < 500 || /*Integer.parseInt(manCount.getText())*/genCount > 2000){
                    System.out.println("Please enter a number between 500 and 2000");
                } else {
                    Thread gen = new Thread(() -> GUI.runGeneration(Integer.parseInt(manCount.getText())));
                    gen.start();
                    //GUI.runGeneration(Integer.parseInt(manCount.getText()));
                }
            } catch (NumberFormatException e){
                System.out.println("Not a valid number! Please enter a whole number.");
            }
        }
        dataGenerated = true;
    }

    /**
     * Method to set up truck combo box
     */
    private void setTruckComboBox(){
        ObservableList<Truck> trucks = FXCollections.observableArrayList(Truck.trucksOnRoad);
        truckCombo.setItems(trucks);
        //truckCombo.setValue(null);
        truckCombo.setConverter(new StringConverter<Truck>(){
            @Override
            public String toString(Truck t){
                return "Truck id: " + t.numOfTruck;
            }

            @Override
            public Truck fromString(String s){
                return null;
            }
        });
        truckCombo.setOnAction(event -> {
            if(truckCombo.getValue() != null){
                Truck t = truckCombo.getValue();
                infoLog.setText(t.infoAboutTruck());
            }
            manCombo.setValue(null);
        });
    }

    /**
     * Method to set up mansion combo box
     */
    private void setManComboBox(){
        ObservableList<AMansion> mansions = FXCollections.observableArrayList(GUI.mansions);
        manCombo.setItems(mansions);
        //manCombo.setValue(null);
        manCombo.setConverter(new StringConverter<AMansion>() {
            @Override
            public String toString(AMansion object) {
                if(object instanceof HQ){
                    return "HQ";
                } else {
                    return ((Mansion)object).name;
                }
            }

            @Override
            public AMansion fromString(String string) {
                return null;
            }
        });
        manCombo.setOnAction(event -> {
            AMansion man = manCombo.getValue();
            if(manCombo.getValue() != null) {
                if (man instanceof HQ) {
                    infoLog.setText(((HQ) man).HQInfo());
                } else {
                    infoLog.setText(((Mansion) man).mansionInfo());
                }
            }
            truckCombo.setValue(null);
        });
    }

    /**
     * Action for import mansions option from menu
     */
    @FXML
    public void importMansions() {
        GUI.mansions = null;
        FileChooser fc = new FileChooser();
        fc.setTitle("Choose mansion source");
        File f = fc.showOpenDialog(consoleLog.getScene().getWindow());

        if(f == null){
            System.out.println("File not chosen! Terminating import!");
        } else {
            long start = System.nanoTime();
            GUI.mansions = FileIO.importFromFile(f);
            long end = System.nanoTime();
            System.out.println("Imported mansions from file in " + (end/1000000 -start/1000000) +"ms.");
            mansionsImported = true;
        }
        startBtn.setDisable(false);
    }

    /**
     * Action for import matrixes option from menu
     */
    @FXML
    public void importMatrixes() {
        GUI.timeMatrix = null;
        GUI.distanceMatrix = null;
        FileChooser fc = new FileChooser();
        fc.setTitle("Choose matrixes source");
        File f = fc.showOpenDialog(consoleLog.getScene().getWindow());

        if(f == null){
            System.out.println("File not chosen! Terminating import!");
        } else {
            long start = System.nanoTime();
            Pomocna p = FileIO.importMatrix(f);
            long end = System.nanoTime();
            GUI.distanceMatrix = p.getDistanceMatrix();
            GUI.timeMatrix = p.getTimeMatrix();
            System.out.println("Imported matrixes from file in " + (end/1000000 -start/1000000) +"ms.");
            matrixesImported = true;
        }
    }

    /**
     * Action for export option from menu
     */
    @FXML
    public void exportToFiles() {
        DirectoryChooser dc = new DirectoryChooser();
        dc.setInitialDirectory(new File(System.getProperty("user.dir")));
        dc.setTitle("Choose destination");
        File f = dc.showDialog(consoleLog.getScene().getWindow());

        if(f == null){
            System.out.println("Directory not chosen! Terminating export!");
        } else {
            System.out.println("Chosen dir: " + f.getPath());
            if(GUI.distanceMatrix == null || GUI.timeMatrix == null){
                System.out.println("Error. Matrixes are corrupted or don't exist! Please generate or import new ones.");
            } else {
                if(GUI.mansions == null){
                    System.out.println("Error. Mansions don't exist or can't be read! Please generate or import new ones.");
                } else {
                    FileIO.exportToFile(GUI.mansions, f);
                    FileIO.exportMatrix(GUI.distanceMatrix, GUI.timeMatrix, f);
                    System.out.println("Finished exporting files. Names: matrixes.txt and mansions.txt");
                }
            }
        }
    }

    /**
     * Action for instruction option from menu
     */
    @FXML
    public void instructions() {
        GUI.instructionStage();
    }

    /**
     * Action for about option from menu
     */
    @FXML
    public void about(){
        GUI.aboutUsStage();
    }

    /**
     * Method that resets data about GUI
     */
    private void dataInfoReset(){
        dataGenerated = false;
        matrixesImported = false;
        mansionsImported = false;
        infoLog.setText("");
    }

    /**
     * Action for show visualization button
     */
    public void showVis() {
        GUI.showVisualization();
    }

    public void makeManualOrder() {
        GUI.manualOrderStage();
    }

    /**
     * Class used to redirect console output stream to the GUI TextArea.
     */
    class TextAreaConsole {
        /** Constant size of the buffer */
        private static final int STRING_BUFFER = 4096;
        /** Constant size of flush interval */
        private static final int FLUSH_INT = 200;
        /** Constant size of text displayed on the output */
        private static final int MAX_TEXT_LEN = 256 * 2048; //256 znaku na radce, 2048 radek - dal se deli 2, takze realne jen 1024 radek (lepsi, rychlejsi)

        /** TextArea to which the console is redirected */
        private final TextArea textArea;
        /** StringBuffer which contains the text of the "console" */
        private final StringBuffer write = new StringBuffer();

        /**
         * The thread for writing the text to TextArea
         */
        private final Thread writeThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (running){
                    try{
                        Thread.sleep(FLUSH_INT);
                        appendText();
                    } catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }
            }
        });

        /**
         * Output stream that writes the text
         */
        private final OutputStream out = new OutputStream() {
            /**
             * Text to be written
             */
            private final byte buffer[] = new byte[STRING_BUFFER];

            /**
             * Overriden method writing a single char
             * @param b char to write
             * @throws IOException
             */
            @Override
            public void write(int b) throws IOException {
                if(pos == STRING_BUFFER){
                    flush();
                }
                buffer[pos] = (byte)b;
                pos++;
            }

            /**
             * Overriden method writing multiple characters
             * @param b byte array of charactes
             * @param off start of the text
             * @param len length of the text
             * @throws IOException
             */
            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                if(pos + len < STRING_BUFFER){
                    System.arraycopy(b, off, buffer, pos, len);
                    pos += len;
                } else {
                    flush();
                    if(len < STRING_BUFFER){
                        System.arraycopy(b, off, buffer, 0 /*pos - je taky 0*/, len);
                    } else {
                        write.append(new String(b, off, len));
                    }
                }
            }

            /**
             * Overriden method that flushes the text
             * @throws IOException
             */
            @Override
            public void flush() throws IOException {
                synchronized (write){
                    write.append(new String(buffer, 0, pos));
                    pos = 0;
                }
            }
        };

        /** Logical run attribute */
        private boolean running = false;
        /** Length of the text*/
        private int pos = 0;

        /** Stream storing original outputs */
        private PrintStream defErr, defOut;

        /**
         * Constructor
         * @param textArea new output
         */
        public TextAreaConsole(TextArea textArea){
            this.textArea = textArea;
            defErr = System.err;
            defOut = System.out;
            writeThread.setDaemon(true);
        }

        /**
         * Start of the redirection
         */
        public void start() {
            PrintStream ps = new PrintStream(out, true);
            //System.setErr(ps);
            System.setOut(ps);
            running = true;
            writeThread.start();
        }

        /**
         * Stop of the redirection
         */
        public void stop(){
            running = false;
            System.setOut(defOut);
            System.setErr(defErr);
            try{
                writeThread.join();
            } catch (InterruptedException e){
                e.printStackTrace();
            }
        }

        /**
         * Method appends text to the end of the TextArea, used in flush
         */
        private void appendText(){
            synchronized (write){
                if(write.length() > 0){
                    final String s = write.toString();
                    write.setLength(0);
                    Platform.runLater(() ->{
                        textArea.appendText(s);
                        int textLen = textArea.getText().length();
                        if(textLen > MAX_TEXT_LEN){
                            textArea.setText(textArea.getText(textLen - MAX_TEXT_LEN / 2, textLen));
                        }
                    });
                }
            }
        }
    }
}
<file_sep>/javadoc/delivery/Truck.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="cs">
<head>
<!-- Generated by javadoc (1.8.0_161) on Sun Dec 02 23:27:13 CET 2018 -->
<title>Truck</title>
<meta name="date" content="2018-12-02">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
    try {
        if (location.href.indexOf('is-external=true') == -1) {
            parent.document.title="Truck";
        }
    }
    catch(err) {
    }
//-->
var methods = {"i0":10,"i1":9,"i2":10,"i3":9,"i4":10,"i5":9,"i6":9,"i7":9,"i8":10,"i9":9,"i10":10,"i11":9,"i12":10,"i13":10,"i14":9};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!--   -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../index-files/index-1.html">Index</a></li>
<li><a href="../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../delivery/Order.html" title="class in delivery"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../index.html?delivery/Truck.html" target="_top">Frames</a></li>
<li><a href="Truck.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!--   -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">delivery</div>
<h2 title="Class Truck" class="title">Class Truck</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>delivery.Truck</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="typeNameLabel">Truck</span>
extends java.lang.Object</pre>
<div class="block">Class of the Truck for deliveries</div>
<dl>
<dt><span class="simpleTagLabel">Author:</span></dt>
<dd><NAME> and <NAME></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.summary">
<!--   -->
</a>
<h3>Field Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Field and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static java.util.Queue&lt;<a href="../delivery/Truck.html" title="class in delivery">Truck</a>&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#launchableTrucks">launchableTrucks</a></span></code>
<div class="block">Queue of the trucks that are in HQ ready to launch</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#MAX_LOAD">MAX_LOAD</a></span></code>
<div class="block">Constant of maximum allowed load</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#numOfTruck">numOfTruck</a></span></code>
<div class="block">Number of truck (id)</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static java.util.List&lt;<a href="../delivery/Truck.html" title="class in delivery">Truck</a>&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#trucksOnRoad">trucksOnRoad</a></span></code>
<div class="block">List of the trucks that are on road</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#UNLOAD_TIME_IN_MIN">UNLOAD_TIME_IN_MIN</a></span></code>
<div class="block">Constant of time needed to unload 1 pallet</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!--   -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../delivery/Truck.html#Truck--">Truck</a></span>()</code>
<div class="block">Parameterless constructor, creating instance of a truck</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!--   -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#addOrder-delivery.Order-">addOrder</a></span>(<a href="../delivery/Order.html" title="class in delivery">Order</a>&nbsp;o)</code>
<div class="block">Method adding order to a truck</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#addToTotalStats--">addToTotalStats</a></span>()</code>
<div class="block">Write statistics when similation is ended</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#canLoad-int-">canLoad</a></span>(int&nbsp;size)</code>
<div class="block">Method tests if truck can load pallets</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#getmileageOfAllTrucks--">getmileageOfAllTrucks</a></span>()</code>
<div class="block">Getter for distance traveled by all trucks</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>java.util.LinkedList&lt;<a href="../delivery/Order.html" title="class in delivery">Order</a>&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#getOrders--">getOrders</a></span>()</code>
<div class="block">Getter for orders</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#gettimeOfAllTrucksOnRoad--">gettimeOfAllTrucksOnRoad</a></span>()</code>
<div class="block">Getter for time spent on road of all trucks</div>
</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#getTotalLoadOfAllTrucks--">getTotalLoadOfAllTrucks</a></span>()</code>
<div class="block">Getter for all pallets delivered by all trucks</div>
</td>
</tr>
<tr id="i7" class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#getTotalMoneyOfAll--">getTotalMoneyOfAll</a></span>()</code>
<div class="block">Getter for total cost of all trucks</div>
</td>
</tr>
<tr id="i8" class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#hasOrder--">hasOrder</a></span>()</code>
<div class="block">Method used for finding out if truck has any orders to deliver</div>
</td>
</tr>
<tr id="i9" class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#checkStateOnRoad-int-">checkStateOnRoad</a></span>(int&nbsp;actualTimeInMin)</code>
<div class="block">Method finds out state of trucks on road</div>
</td>
</tr>
<tr id="i10" class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#infoAboutTruck--">infoAboutTruck</a></span>()</code>
<div class="block">Method returns text info about truck</div>
</td>
</tr>
<tr id="i11" class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#nextDay--">nextDay</a></span>()</code>
<div class="block">Method moving the trucks to the next day of simulation</div>
</td>
</tr>
<tr id="i12" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#sendOnRoad-int-">sendOnRoad</a></span>(int&nbsp;timeOfStartInMin)</code>
<div class="block">Method sends truck on road</div>
</td>
</tr>
<tr id="i13" class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#truckTag--">truckTag</a></span>()</code>
<div class="block">Method creates truck tag used in statistics</div>
</td>
</tr>
<tr id="i14" class="altColor">
<td class="colFirst"><code>static java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../delivery/Truck.html#wholeSimStats--">wholeSimStats</a></span>()</code>
<div class="block">Method for writing stats from the whole simulation</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!--   -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ FIELD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.detail">
<!--   -->
</a>
<h3>Field Detail</h3>
<a name="MAX_LOAD">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>MAX_LOAD</h4>
<pre>public static final&nbsp;int MAX_LOAD</pre>
<div class="block">Constant of maximum allowed load</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../constant-values.html#delivery.Truck.MAX_LOAD">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="UNLOAD_TIME_IN_MIN">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>UNLOAD_TIME_IN_MIN</h4>
<pre>public static final&nbsp;int UNLOAD_TIME_IN_MIN</pre>
<div class="block">Constant of time needed to unload 1 pallet</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../constant-values.html#delivery.Truck.UNLOAD_TIME_IN_MIN">Constant Field Values</a></dd>
</dl>
</li>
</ul>
<a name="launchableTrucks">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>launchableTrucks</h4>
<pre>public static&nbsp;java.util.Queue&lt;<a href="../delivery/Truck.html" title="class in delivery">Truck</a>&gt; launchableTrucks</pre>
<div class="block">Queue of the trucks that are in HQ ready to launch</div>
</li>
</ul>
<a name="trucksOnRoad">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>trucksOnRoad</h4>
<pre>public static&nbsp;java.util.List&lt;<a href="../delivery/Truck.html" title="class in delivery">Truck</a>&gt; trucksOnRoad</pre>
<div class="block">List of the trucks that are on road</div>
</li>
</ul>
<a name="numOfTruck">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>numOfTruck</h4>
<pre>public&nbsp;int numOfTruck</pre>
<div class="block">Number of truck (id)</div>
</li>
</ul>
</li>
</ul>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!--   -->
</a>
<h3>Constructor Detail</h3>
<a name="Truck--">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Truck</h4>
<pre>public&nbsp;Truck()</pre>
<div class="block">Parameterless constructor, creating instance of a truck</div>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!--   -->
</a>
<h3>Method Detail</h3>
<a name="addOrder-delivery.Order-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>addOrder</h4>
<pre>public&nbsp;void&nbsp;addOrder(<a href="../delivery/Order.html" title="class in delivery">Order</a>&nbsp;o)
              throws java.lang.Exception</pre>
<div class="block">Method adding order to a truck</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>o</code> - order that is to be added</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.Exception</code></dd>
</dl>
</li>
</ul>
<a name="sendOnRoad-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sendOnRoad</h4>
<pre>public&nbsp;void&nbsp;sendOnRoad(int&nbsp;timeOfStartInMin)</pre>
<div class="block">Method sends truck on road</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>timeOfStartInMin</code> - time when the truck sets out</dd>
</dl>
</li>
</ul>
<a name="hasOrder--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>hasOrder</h4>
<pre>public&nbsp;boolean&nbsp;hasOrder()</pre>
<div class="block">Method used for finding out if truck has any orders to deliver</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>true or false</dd>
</dl>
</li>
</ul>
<a name="canLoad-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>canLoad</h4>
<pre>public&nbsp;boolean&nbsp;canLoad(int&nbsp;size)</pre>
<div class="block">Method tests if truck can load pallets</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>size</code> - number of pallets to be loaded</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>true or false</dd>
</dl>
</li>
</ul>
<a name="checkStateOnRoad-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>checkStateOnRoad</h4>
<pre>public static&nbsp;void&nbsp;checkStateOnRoad(int&nbsp;actualTimeInMin)</pre>
<div class="block">Method finds out state of trucks on road</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>actualTimeInMin</code> - time of simulation</dd>
</dl>
</li>
</ul>
<a name="getOrders--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getOrders</h4>
<pre>public&nbsp;java.util.LinkedList&lt;<a href="../delivery/Order.html" title="class in delivery">Order</a>&gt;&nbsp;getOrders()</pre>
<div class="block">Getter for orders</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>LinkedList of orders</dd>
</dl>
</li>
</ul>
<a name="gettimeOfAllTrucksOnRoad--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>gettimeOfAllTrucksOnRoad</h4>
<pre>public static&nbsp;int&nbsp;gettimeOfAllTrucksOnRoad()</pre>
<div class="block">Getter for time spent on road of all trucks</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>time</dd>
</dl>
</li>
</ul>
<a name="getmileageOfAllTrucks--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getmileageOfAllTrucks</h4>
<pre>public static&nbsp;int&nbsp;getmileageOfAllTrucks()</pre>
<div class="block">Getter for distance traveled by all trucks</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>distance in km</dd>
</dl>
</li>
</ul>
<a name="getTotalLoadOfAllTrucks--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getTotalLoadOfAllTrucks</h4>
<pre>public static&nbsp;int&nbsp;getTotalLoadOfAllTrucks()</pre>
<div class="block">Getter for all pallets delivered by all trucks</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>number of pallets</dd>
</dl>
</li>
</ul>
<a name="getTotalMoneyOfAll--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getTotalMoneyOfAll</h4>
<pre>public static&nbsp;int&nbsp;getTotalMoneyOfAll()</pre>
<div class="block">Getter for total cost of all trucks</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>cost in kc</dd>
</dl>
</li>
</ul>
<a name="nextDay--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>nextDay</h4>
<pre>public static&nbsp;void&nbsp;nextDay()</pre>
<div class="block">Method moving the trucks to the next day of simulation</div>
</li>
</ul>
<a name="addToTotalStats--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>addToTotalStats</h4>
<pre>public static&nbsp;void&nbsp;addToTotalStats()</pre>
<div class="block">Write statistics when similation is ended</div>
</li>
</ul>
<a name="infoAboutTruck--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>infoAboutTruck</h4>
<pre>public&nbsp;java.lang.String&nbsp;infoAboutTruck()</pre>
<div class="block">Method returns text info about truck</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>text info</dd>
</dl>
</li>
</ul>
<a name="truckTag--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>truckTag</h4>
<pre>public&nbsp;java.lang.String&nbsp;truckTag()</pre>
<div class="block">Method creates truck tag used in statistics</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>String tag</dd>
</dl>
</li>
</ul>
<a name="wholeSimStats--">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>wholeSimStats</h4>
<pre>public static&nbsp;java.lang.String&nbsp;wholeSimStats()</pre>
<div class="block">Method for writing stats from the whole simulation</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>String of all stats</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!--   -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../index-files/index-1.html">Index</a></li>
<li><a href="../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../delivery/Order.html" title="class in delivery"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../index.html?delivery/Truck.html" target="_top">Frames</a></li>
<li><a href="Truck.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!--   -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>
<file_sep>/README.txt
1) Zda se mi, že se občas generování matice sousednosti zasekne v nekonečném cyklu.
	-generování jsem snad fixnul, bohužel jsem si to přepsal, ale znovu jsem to opravoval, tak snad správně

2) Je potřeba dodělat výstup vlákna simulace do externího okna a také zápis do souboru.
	-do externího okna je teď výpis snad všeho. Do souboru mám importy a export (trochu jsem ošetřil vstupy, ale asi by to chtělo ještě testnout,
		kdyby si se nudil). Jinak cheš abych udělal výstup i cest do souboru? 

3) Simulace nefunguje
	-tak něják trošičku jo, to je na tobě ;)
	
4) Kdyby si na tom začel pracovat tak mi dej vědět na čem budeš pracovat.   //TODO

5) Budeme potřebovat roztřídit ten bordel v package generation do více balíčků kvůli budoucí dokumentaci.
	-naprosto souhlasím
	

6) Bug na trucku. Občas hodí nakládání 0 objednávek. Občas nakládá o paletu víc než má. Některé trucky mají nesmyslné doby, kdy vyrážejí na cestu.
	(můj tip - někde tomu trucku v simulaci předáváš čas v s. a zapomněl si to převést na minuty). Možná spolu souvisí špatné množství palet a čas.
	Také se velmi často stává, že 1 truck veze třeba 4 objednávky po 1 do stejného sídla. Nevím jestli když sídlo chce objednat 4 tak objedná 4x1 nebo co,	
	ale asi by to chtělo se na to podívat.     ------- chyba nastava pri dni dva a více.. někde jsem na něco zapomněl  (zítra na to kouknu)

7) Když začíná den, tak má 0 objednávek. Z toho jak to chápu, tak na začátku dne, v 6 hodin už by měl znát X objednávek a v průběhu dne by jich měl dostávat čím dál míň.
  -------objednávky z minulých dní bych přenášel do dalších dní. A ano objednávky by měli postupně klesat podle času.

8) Když přeruším simulaci, vygeneruji nové data a spustím znovu simulaci, tak "pokračuje" v předchozí simulaci. Jestli se ti tuto nechce řešit, tak jednoduše udělám, že pokud si
	zastavil simulaci, tak aby si mohl pustit novou, tak musíš restartovat program. (Což bych asi zvolil, pokud nebudem mít moře času, s čímž moc nepočítam :D)
	
9) GUI je na dobré cestě, když tak si ho zkus proklikat, aby si otestoval ošetření vstupů, jestli jsem nějáké zapomněl..
	Stále na GUI jsou věci co vylepšovat, ale až dodělam ještě pár funkčností (hlavně menu, kde zatím fungují jen importy a exporty souborů), tak si od GUI dam pauzu,
	pokud budeš na GUI chtít něco změnit/ předělat tak buď napiš nebo se s tim můžeš zkusit potrápit sám
	
10) Když se naimportují data ze souborů, tak simulace negeneruje Trucky. Tuto si myslím, že vím proč je, takže když tak to udělám, kdyby si na to koukal, tak řekni.

*) To je asi všechno GL



27.11 

11) třeba dodělat ošetření startu simulaci bez vygenerovaných komponentů
12) umožnit zastavovani a nasledneho spousteni simulace. Hazi to chybu kdyz je otevřeno    viz bod 8).. neřekl bych že je chyba v zastavování
13) při zmáčknutí tlačítka exit je třeba vypnout pomocí System.close(0) nebo jak to je a zeptat se ho zda chce ulozit do souboru
14) a zacatku každeho dne uložit výsledky do souboru   (ptá se na to u odevzdavani)
15) ve třídě Truck jsou všechny statistiky potřebné jak je zadáno v zadání


<file_sep>/src/delivery/Order.java
package delivery;

import java.util.LinkedList;

import objects.Mansion;

/**
 * Class of order
 * @author <NAME> a <NAME>
 */
public class Order {

	public static LinkedList<Order> manualOrders= new LinkedList<Order>();
	
	
	/** Number of all orders */
	public static int numberOfAllOrders =0;

	/** Instance of the subscriber of the order */
	private final Mansion subscriber;
	/** Amount of pallets ordered */
	private int amount;
	/** Number(id) of order */
	public int orderNum=0;
	/** Expected time of delivery in min */
	private int probableDeliveryInMin=0;

	private boolean manual = false;
	
	/**
	 * Constructor of the order
	 * @param sub mansion creating the order
	 * @param am amount of pallets to be ordered
	 */
	public Order(Mansion sub, int am, boolean manual) {
		this.subscriber=sub;
		this.amount=am;
		numberOfAllOrders++;
		this.orderNum= numberOfAllOrders;
		this.manual=manual;
		if(manual) {
			manualOrders.add(this);
			System.out.print("MANUAL ");
		}
		System.out.println("Order n: "+orderNum+" for "+am+" pallet has been made by mansion n: " + subscriber.iD + "!");
	}

	/**
	 * Method sets probable time of delivery
	 * @param timeInMin expected new time
	 */
	public void setProbableTime(int timeInMin) {
		this.probableDeliveryInMin=timeInMin;
	}

	/**
	 * Method returns probable time of delivery
	 * @return time in min
	 */
	public int getProbableTime() {
		return this.probableDeliveryInMin;
	}


	/**
	 * Getter of the amount of pallets
	 * @return amount
	 */
	public int getAmount() {
		return amount;
	}

	/**
	 * Getter of the mansion creating order
	 * @return mansion
	 */
	public Mansion getSubscriber() {
		return subscriber;
	}

	/**
	 * Method to give information about the order in text from.
	 * @return string
	 */
	@Override
	public String toString(){
		if(manual){
			return "	MANUAL ORDER: " + orderNum + ", by mansion: " + subscriber.iD + ", amount: " + amount + " pallets";
		} else {
			return "	Order: " + orderNum + ", by mansion: " + subscriber.iD + ", amount: " + amount + " pallets";
		}
	}
}
