Resource extends NetworkElement { public void setCapacity(double newCapacity , Map<Resource,Double> newCapacityIOccupyInBaseResourcesMap) { checkAttachedToNetPlanObject(); netPlan.checkIsModifiable(); if (newCapacityIOccupyInBaseResourcesMap == null) newCapacityIOccupyInBaseResourcesMap = new TreeMap<Resource,Double> (); final boolean isUsedByUpperResources = !this.getUpperResources().isEmpty(); for (Entry<Resource,Double> entry : newCapacityIOccupyInBaseResourcesMap.entrySet()) { netPlan.checkInThisNetPlan(entry.getKey()); if (isUsedByUpperResources && !this.capacityIOccupyInBaseResource.keySet().contains(entry.getKey())) throw new Net2PlanException ("When resizing a resource capacity, we cannot increase its set of base resources"); if (entry.getValue() < 0) throw new Net2PlanException ("The capacity occupied in a base resource cannot be negative"); } if (newCapacity < 0) throw new Net2PlanException ("The capacity of a resource cannot be negative"); this.capacity = newCapacity; this.capacityIOccupyInBaseResource.putAll (newCapacityIOccupyInBaseResourcesMap); for (Entry<Resource,Double> entry : newCapacityIOccupyInBaseResourcesMap.entrySet()) entry.getKey().setUpperResourceOccupiedCapacity(this , entry.getValue()); updateTotalOccupiedCapacity(); } 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 testSetCapacity () { assertEquals(upperResource.getOccupiedCapacity() , 1.0 , 0.0); assertEquals(baseResource.getOccupiedCapacity() , 6.0 , 0.0); final SortedMap<Resource , Double> sm = new TreeMap<> (); sm.put(baseResource , 3.0); upperResource.setCapacity(10 , sm); np.checkCachesConsistency(); assertEquals(upperResource.getCapacity() , 10.0 , 0.0); assertEquals(upperResource.getOccupiedCapacity() , 1.0 , 0.0); assertEquals(baseResource.getCapacity() , 10.0 , 0.0); assertEquals(baseResource.getOccupiedCapacity() , 4.0 , 0.0); }