void copyFrom (SharedRiskGroup origin) { if ((this.id != origin.id) || (this.index != origin.index)) throw new RuntimeException ("Bad"); if ((this.netPlan == null) || (origin.netPlan == null) || (this.netPlan == origin.netPlan)) throw new RuntimeException ("Bad"); this.meanTimeToFailInHours = origin.meanTimeToFailInHours; this.meanTimeToRepairInHours = origin.meanTimeToRepairInHours; if (origin.isDynamicSrg()) { this.linksIfNonDynamic.clear(); this.nodesIfNonDynamic.clear(); try { this.dynamicSrgImplementation = (DynamicSrgImplementation) Class.forName(origin.dynamicSrgImplementation.getClass().getName()).newInstance(); } catch (Exception e) { e.printStackTrace(); throw new Net2PlanException ("SRG Dynamic initialization error");} this.dynamicSrgImplementation.initialize(origin.dynamicSrgImplementation.getInitializationString (), this.netPlan); } else { this.linksIfNonDynamic.clear (); for (Link e : origin.linksIfNonDynamic) this.linksIfNonDynamic.add(this.netPlan.getLinkFromId (e.id)); this.nodesIfNonDynamic.clear (); for (Node n : origin.nodesIfNonDynamic) this.nodesIfNonDynamic.add(this.netPlan.getNodeFromId (n.id)); this.dynamicSrgImplementation = null; } }
/** * <p>Returns the set of links associated to the SRG (fail, when the SRG is in failure state).</p> * @return The set of failing links, as an unmodifiable set */ public SortedSet<Link> getLinksAllLayers() { if (isDynamicSrg()) return dynamicSrgImplementation.getLinksAllLayers(); return Collections.unmodifiableSortedSet(linksIfNonDynamic); }
/** * <p>Returns the set of nodes associated to the SRG (fail, when the SRG is in failure state)</p> * @return The set of failing nodes, as an unmodifiable set */ public SortedSet<Node> getNodes() { if (isDynamicSrg()) return dynamicSrgImplementation.getNodes(); return Collections.unmodifiableSortedSet(nodesIfNonDynamic); }
boolean isDeepCopy (SharedRiskGroup e2) { if (!super.isDeepCopy(e2)) return false; if (this.meanTimeToFailInHours != e2.meanTimeToFailInHours) return false; if (this.meanTimeToRepairInHours != e2.meanTimeToRepairInHours) return false; if (this.isDynamicSrg()) { if (!e2.isDynamicSrg()) return false; if (!this.dynamicSrgImplementation.getClass().getName().equals(e2.dynamicSrgImplementation.getClass().getName())) return false; if (!this.dynamicSrgImplementation.getInitializationString().equals(e2.dynamicSrgImplementation.getInitializationString())) return false; if (!NetPlan.isDeepCopy(this.getLinksAllLayers() , e2.getLinksAllLayers())) return false; if (!NetPlan.isDeepCopy(this.getNodes() , e2.getNodes())) return false; } else { if (e2.isDynamicSrg()) return false; if (!NetPlan.isDeepCopy(this.nodesIfNonDynamic , e2.nodesIfNonDynamic)) return false; if (!NetPlan.isDeepCopy(this.linksIfNonDynamic, e2.linksIfNonDynamic)) return false; } return true; }
SharedRiskGroup (NetPlan netPlan , long id , int index , String className , String dynamicInitializationString , double meanTimeToFailInHours , double meanTimeToRepairInHours , AttributeMap attributes) { super (netPlan , id , index , attributes); this.setName ("Srg-" + index); this.nodesIfNonDynamic = new TreeSet<> (); this.linksIfNonDynamic = new TreeSet<> (); this.meanTimeToFailInHours = meanTimeToFailInHours; this.meanTimeToRepairInHours = meanTimeToRepairInHours; try { this.dynamicSrgImplementation = (DynamicSrgImplementation) Class.forName(className).newInstance(); } catch (Exception e) { e.printStackTrace(); throw new Net2PlanException ("SRG Dynamic initialization error");} this.dynamicSrgImplementation.initialize(dynamicInitializationString , netPlan); }
/** * <p>Removes this SRG.</p> */ public void remove() { checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); if (!isDynamicSrg()) { for (Node node : nodesIfNonDynamic) node.cache_nodeNonDynamicSRGs.remove (this); for (Link link : linksIfNonDynamic) link.cache_nonDynamicSrgs.remove (this); } else { dynamicSrgImplementation.remove(); // release memory } for (String tag : tags) netPlan.cache_taggedElements.get(tag).remove(this); netPlan.cache_id2srgMap.remove (id); NetPlan.removeNetworkElementAndShiftIndexes(netPlan.srgs , index); if (isDynamicSrg()) netPlan.cache_dynamicSrgs.remove(this); final NetPlan npOld = this.netPlan; removeId(); if (ErrorHandling.isDebugEnabled()) npOld.checkCachesConsistency(); }
originSrg.getDynamicSrgImplementation().getInitializationString() , originSrg.meanTimeToFailInHours, originSrg.meanTimeToRepairInHours, originSrg.attributes); for (String tag : originSrg.getTags ()) newElement.addTag (tag);
writer.writeAttribute("dynamicSrgConfigString", srg.getDynamicSrgImplementation().getInitializationString());