private HashMap<String, LinkedList<Block>> setSwitchList(LinkedList<Block> blockSection) { Iterator<Block> blockIterator = this.section.iterator(); HashMap<String, LinkedList<Block>> switchMap = new HashMap<String, LinkedList<Block>>(); while (blockIterator.hasNext()) { Block currBlock = blockIterator.next(); if (currBlock.getMasterSwitch()) { LinkedList<Block> blocks = (LinkedList<Block>) currBlock.getSwitchList(); blocks.addFirst(currBlock); switchMap.put(Integer.toString(currBlock.getSwitchNum()), blocks); } } return switchMap; }
/** checks PLC logic and current switch engagement, switches engagement if different */ @Override public boolean engageSwitch(String switchName, boolean engagement) { if (this.switchList.containsKey(switchName)) { Iterator<Block> switchBlockIterator = this.switchList.get(switchName).iterator(); while (switchBlockIterator.hasNext()) { Block currBlock = switchBlockIterator.next(); if (currBlock.getMasterSwitch()) { if (currBlock.isSwitchEngaged() != engagement && plcProgramA != null && plcProgramB != null && plcProgramA.engageSwitch(currBlock) && plcProgramB.engageSwitch(currBlock)) { currBlock.setSwitchEngagement(); this.ctc.switchChanged(switchName, currBlock.getBlockNumber(), engagement); return true; } } } return false; } else { System.err.println("ERROR: THIS TC DOES NOT CONTAIN SWITCH " + switchName); return false; } }