Ejemplo n.º 1
0
  public Block(String[] splitStrings, Block lastCreated) {
    // TODO Auto-generated constructor stub

    line = splitStrings[0];
    section = splitStrings[1];
    blockNumber = Integer.parseInt(splitStrings[2]);
    blockLength = Double.parseDouble(splitStrings[3]);
    grade = Double.parseDouble(splitStrings[4]);
    speedLimit = Integer.parseInt(splitStrings[5]);
    station = splitStrings[6];
    switchBlock = splitStrings[7];
    underground = splitStrings[8];
    elevation = Double.parseDouble(splitStrings[9]);
    cumElevation = Double.parseDouble(splitStrings[10]);
    switchNumber = splitStrings[11];
    arrow = splitStrings[12]; // head no longer needed ???
    direction = Integer.parseInt(splitStrings[13]);
    crossing = splitStrings[14];
    switchType = splitStrings[15];

    if (station.equals("TO YARD") || station.equals("TO YARD/FROM YARD")) {
      toYard = true;
    }
    if (station.equals("FROM YARD") || station.equals("TO YARD/FROM YARD")) {
      fromYard = true;
    }

    if (toYard == false && fromYard == false && station.length() > 0) {
      String[] stationStuff = station.split("-");
      station = stationStuff[0];
      stationSide = stationStuff[1];
    }

    if (lastCreated == null) {

    } else if (direction == 1 || direction == 2) // set the path
    {
      next = lastCreated;

      if (next.getDirection() == -1) next.setNext(this);

      next.setPrevious(this);
    } else if (direction == -1) {
      previous = lastCreated;

      if (previous.getDirection() == 2) previous.setPrevious(this);
      else previous.setNext(this);
    }

    // switches
    // stations
    // crossings
  }
Ejemplo n.º 2
0
	public void removeLast(){

		endedBlocks.addBlock(tail.getName(), tail.getProcNo());			// tar vare på blokken som avsluttes

		tail = tail.getPrevious();							// tailen settes til sin egen forgjenger
		tail.setNext(head);									// setter "tailen" sin neste til å være "head"
		head.setPrevious(tail);								// setter "head" sin forrige til å være tail
		numLevels--;										// reduserer antalle nivåer med 1
	}
Ejemplo n.º 3
0
	public void addBlock(String blockName, int procNo){

		if (isEmpty()) {									// dersom "Blocks" ikke inneholder noen "Block" fra før
			head = new Block(blockName, procNo);			// head settes lik en ny blokk som automatisk får blokknivå 0
			tail = head;									// tail = head (vi har jo bare en blokk!)
		} else {
			tail.addBlock(new Block(blockName, procNo));	// "tail" får en ny blokk
			tail.getNext().setPrevious(tail);				// setter den nye blokken (tail.getNext) sin forrige til å være lik "tail"
			tail = tail.getNext();							// vi forandrer "tail" til å bli den nye blokken
			tail.setNext(head);								// setter "tail" sin neste til å være lik "head"
			head.setPrevious(tail);							// setter "head" sin forrige til å være "tail"
			
			// vi må sette previous!!!
		}
		numLevels++;										// øker antall blokknivåer med 1
	}