private static boolean pathsEqual(OPath p1, OPath p2) { Portal toPortal1 = p1.getToPortal(); Portal fromPortal1 = p1.getFromPortal(); Portal toPortal2 = p2.getToPortal(); Portal fromPortal2 = p2.getFromPortal(); boolean testSettings = false; if (toPortal1 != null) { if ((toPortal1.equals(toPortal2) || toPortal1.equals(fromPortal2))) { if (fromPortal1 != null) { if (fromPortal1.equals(fromPortal2) || fromPortal1.equals(toPortal2)) { testSettings = true; } } else { if (toPortal2 == null || fromPortal2 == null) { testSettings = true; } } } } else if (toPortal2 == null) { // i.e. toPortal2 matches toPortal1==null if (fromPortal1 != null && fromPortal1.equals(fromPortal2)) { testSettings = true; } } else if (fromPortal2 == null) { // i.e. fromPortal2 matches toPortal1==null if (fromPortal1 != null && fromPortal1.equals(toPortal2)) { testSettings = true; } } if (testSettings) { java.util.List<BeanSetting> setting1 = p1.getSettings(); java.util.List<BeanSetting> setting2 = p2.getSettings(); if (setting1.size() != setting2.size()) { return false; } if (setting1.size() == 0) { // no turnouts in paths, but portals the same return true; } Iterator<BeanSetting> it = setting1.iterator(); while (it.hasNext()) { BeanSetting bs1 = it.next(); Iterator<BeanSetting> iter = setting2.iterator(); while (iter.hasNext()) { BeanSetting bs2 = iter.next(); if (bs1.getBean().equals(bs2.getBean()) && bs1.getSetting() == bs2.getSetting()) { return true; } } } } return false; }
private static Element storePath(OPath path) { Element elem = new Element("path"); elem.setAttribute("pathName", path.getName()); elem.setAttribute("blockName", "" + path.getBlock().getSystemName()); Portal portal = path.getFromPortal(); if (portal != null) { elem.setAttribute("fromPortal", portal.getName()); } portal = path.getToPortal(); if (portal != null) { elem.setAttribute("toPortal", portal.getName()); } List<BeanSetting> list = path.getSettings(); for (int i = 0; i < list.size(); i++) { BeanSetting bs = list.get(i); Element e = new Element("setting"); // Turnout to = (Turnout)bs.getBean(); e.setAttribute("turnout", bs.getBeanName()); e.setAttribute("set", "" + bs.getSetting()); elem.addContent(e); } elem.setAttribute("fromDirection", "" + path.getFromBlockDirection()); elem.setAttribute("toDirection", "" + path.getToBlockDirection()); elem.setAttribute("length", "" + path.getLengthMm()); return elem; }