Resource extends NetworkElement { void copyFrom (Resource 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.type = origin.type; this.name = origin.name; this.hostNode = origin.hostNode.isPresent()? Optional.of(this.netPlan.getNodeFromId (origin.hostNode.get().id)) : Optional.empty(); this.capacityMeasurementUnits = origin.capacityMeasurementUnits; this.capacity = origin.capacity; this.cache_totalOccupiedCapacity = origin.cache_totalOccupiedCapacity; this.processingTimeToTraversingTrafficInMs = origin.processingTimeToTraversingTrafficInMs; this.urlIcon = origin.urlIcon; this.capacityUpperResourcesOccupyInMe = new TreeMap<Resource,Double> (); for (Entry<Resource,Double> entry : origin.capacityUpperResourcesOccupyInMe.entrySet()) { final Resource resourceThisNp = this.netPlan.getResourceFromId(entry.getKey().id); if (resourceThisNp == null) throw new RuntimeException ("Bad"); this.capacityUpperResourcesOccupyInMe.put(resourceThisNp , entry.getValue()); } this.capacityIOccupyInBaseResource = new TreeMap<Resource,Double> (); for (Entry<Resource,Double> entry : origin.capacityIOccupyInBaseResource.entrySet()) { final Resource resourceThisNp = this.netPlan.getResourceFromId(entry.getKey().id); if (resourceThisNp == null) throw new RuntimeException ("Bad"); this.capacityIOccupyInBaseResource.put(resourceThisNp , entry.getValue()); } this.cache_traversingRoutesAndOccupiedCapacitiesIfNotFailingRoute = new TreeMap<Route,Double> (); for (Entry<Route,Double> originRoute : origin.cache_traversingRoutesAndOccupiedCapacitiesIfNotFailingRoute.entrySet()) { final Route routeThisNp = this.netPlan.getRouteFromId(originRoute.getKey().id); if (routeThisNp == null) throw new RuntimeException ("Bad"); this.cache_traversingRoutesAndOccupiedCapacitiesIfNotFailingRoute.put(this.netPlan.getRouteFromId(originRoute.getKey().id) , originRoute.getValue()); } } Resource(NetPlan netPlan , long id , int index , String type , String name , Optional<Node> hostNode , 
			double capacity , String capacityMeasurementUnits,
			Map<Resource,Double> capacityIOccupyInBaseResource , double processingTimeToTraversingTraffic , 
			AttributeMap attributes); double getUtilization(); boolean isOversubscribed(); double getProcessingTimeToTraversingTrafficInMs(); void setProcessingTimeToTraversingTrafficInMs(double time); URL getUrlIcon(); void setUrlIcon(URL url); String getType(); Optional<Node> getHostNode(); boolean iAttachedToANode(); String getCapacityMeasurementUnits(); void setCapacityMeasurementUnits(String units); double getCapacity(); double getOccupiedCapacity(); boolean isHavingMoreThanOneBaseResourceWithTheSameType(); SortedSet<Resource> getBaseResources(); SortedSet<Resource> getUpperResources(); double getCapacityOccupiedInBaseResource(Resource baseResource); double getCapacityOccupiedByUpperResource(Resource upperResource); SortedMap<Resource, Double> getCapacityOccupiedInBaseResourcesMap(); SortedMap<Resource, Double> getCapacityOccupiedByUpperResourcesMap(); SortedSet<Demand> getTraversingDemands(); SortedSet<Route> getTraversingRoutes(); double getTraversingRouteOccupiedCapacity(Route route); SortedMap<Route,Double> getTraversingRouteOccupiedCapacityMap(); void setCapacity(double newCapacity , Map<Resource,Double> newCapacityIOccupyInBaseResourcesMap); void remove(); @Override String toString(); void dettachFromNode(); void attachToNode(Node node);  }
@Test public void testCopyFrom () { NetPlan np2 = new NetPlan (); np2.copyFrom(np.copy()); np2.checkCachesConsistency(); assertTrue (np.isDeepCopy(np2)); assertTrue (np2.isDeepCopy(np)); }