Resource extends NetworkElement { public void remove() { checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); for (Route r : new ArrayList<> (cache_traversingRoutesAndOccupiedCapacitiesIfNotFailingRoute.keySet())) r.remove(); for (Resource upperResource : new ArrayList<> (capacityUpperResourcesOccupyInMe.keySet())) upperResource.remove(); for (Resource baseResource : new ArrayList<> (capacityIOccupyInBaseResource.keySet())) baseResource.removeUpperResourceOccupation(this); netPlan.cache_id2ResourceMap.remove (id); SortedSet<Resource> resourcesThisType = netPlan.cache_type2Resources.get(type); if (!resourcesThisType.contains(this)) throw new RuntimeException ("Bad"); if (resourcesThisType.size() == 1) netPlan.cache_type2Resources.remove (type); else resourcesThisType.remove(this); if (hostNode.isPresent()) hostNode.get().cache_nodeResources.remove(this); for (String tag : tags) netPlan.cache_taggedElements.get(tag).remove(this); NetPlan.removeNetworkElementAndShiftIndexes(netPlan.resources , index); final NetPlan npOld = this.netPlan; removeId(); if (ErrorHandling.isDebugEnabled()) npOld.checkCachesConsistency(); } 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 testGetResourcesOfType () { assertEquals(np.getResources("baseType"), Collections.singleton(baseResource)); assertEquals(np.getResources("upperType"), Collections.singleton(upperResource)); assertEquals(np.getResources("xxx"), Collections.emptySet()); upperResource.remove(); assertEquals(np.getResources("upperType"), Collections.emptySet()); baseResource.remove(); assertEquals(np.getResources("baseType"), Collections.emptySet()); }
@Test public void testGetResources () { assertEquals(hostNode.getResources("baseType"), Collections.singleton(baseResource)); assertEquals(hostNode.getResources("upperType"), Collections.singleton(upperResource)); assertEquals(hostNode.getResources("xxx"), Collections.emptySet()); Set<Resource> res = new HashSet<Resource> (); res.add(baseResource); res.add (upperResource); assertEquals(hostNode.getResources(), res); assertEquals(hostNode.getResources("upperType" , "baseType"), res); baseResource.remove(); assertEquals(hostNode.getResources("baseType"), Collections.emptySet()); assertEquals(hostNode.getResources("upperType"), Collections.emptySet()); assertEquals(hostNode.getResources("xxx"), Collections.emptySet()); assertEquals(hostNode.getResources(), Collections.emptySet()); assertEquals(hostNode.getResources("upperType" , "baseType"), Collections.emptySet()); }