Inline static factory methods in BandwidthResource
Change-Id: I8ac7fbaea5c81c9558f88f6ac88bcf581466d073
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
index 62d9d02..6b22b75 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
@@ -16,6 +16,7 @@
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
+import org.onlab.util.Bandwidth;
import org.slf4j.Logger;
import org.onlab.util.KryoNamespace;
import org.onlab.util.PositionalParameterStringFormatter;
@@ -67,8 +68,8 @@
private final Logger log = getLogger(getClass());
- private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000);
- private static final BandwidthResource EMPTY_BW = BandwidthResource.bps(0);
+ private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000));
+ private static final BandwidthResource EMPTY_BW = new BandwidthResource(Bandwidth.bps(0));
// Smallest non-reserved MPLS label
private static final int MIN_UNRESERVED_LABEL = 0x10;
@@ -154,7 +155,7 @@
String strBw = link.annotations().value(BANDWIDTH);
if (strBw != null) {
try {
- bandwidth = BandwidthResource.mbps(Double.parseDouble(strBw));
+ bandwidth = new BandwidthResource(Bandwidth.mbps(Double.parseDouble(strBw)));
} catch (NumberFormatException e) {
// do nothings
bandwidth = null;
@@ -237,7 +238,8 @@
}
}
- free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(BandwidthResource.bps(freeBw))));
+ free.put(type, Sets.newHashSet(
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(freeBw)))));
break;
case LAMBDA:
Set<? extends ResourceAllocation> lmd = caps.get(type);
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
index 1bbdbc1..00141a2 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
@@ -30,6 +30,7 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.Bandwidth;
import org.onlab.util.PositionalParameterStringFormatter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Link;
@@ -80,9 +81,9 @@
private final Logger log = getLogger(getClass());
- private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000);
+ private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000));
- private static final BandwidthResource EMPTY_BW = BandwidthResource.bps(0);
+ private static final BandwidthResource EMPTY_BW = new BandwidthResource(Bandwidth.bps(0));
// table to store current allocations
/** LinkKey -> List<LinkResourceAllocations>. */
@@ -174,7 +175,7 @@
String strBw = link.annotations().value(bandwidthAnnotation);
if (strBw != null) {
try {
- bandwidth = BandwidthResource.mbps(Double.parseDouble(strBw));
+ bandwidth = new BandwidthResource(Bandwidth.mbps(Double.parseDouble(strBw)));
} catch (NumberFormatException e) {
// do nothings
bandwidth = null;
@@ -262,7 +263,8 @@
}
}
- free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(BandwidthResource.bps(freeBw))));
+ free.put(type, Sets.newHashSet(
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(freeBw)))));
break;
}
diff --git a/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
index 6df10a6..304177d 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
@@ -21,6 +21,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.util.Bandwidth;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -172,7 +173,7 @@
final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes);
assertNotNull(alloc);
- assertEquals(BandwidthResource.mbps(1000.0), alloc.bandwidth());
+ assertEquals(new BandwidthResource(Bandwidth.mbps(1000.0)), alloc.bandwidth());
}
/**
@@ -209,7 +210,7 @@
ImmutableSet.of(link))
.build();
final ResourceAllocation allocation =
- new BandwidthResourceAllocation(BandwidthResource.mbps(900.0));
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(900.0)));
final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
final LinkResourceAllocations allocations =
@@ -230,7 +231,7 @@
ImmutableSet.of(link))
.build();
final ResourceAllocation allocation =
- new BandwidthResourceAllocation(BandwidthResource.mbps(9000.0));
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(9000.0)));
final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
final LinkResourceAllocations allocations =
@@ -258,7 +259,7 @@
ImmutableSet.of(link))
.build();
final ResourceAllocation allocation =
- new BandwidthResourceAllocation(BandwidthResource.mbps(900.0));
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(900.0)));
final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
final LinkResourceAllocations allocations =
diff --git a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
index 94aa5ee..ad3e440 100644
--- a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
+++ b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
@@ -355,7 +355,7 @@
.build();
Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
- ImmutableSet.of(new BandwidthResourceAllocation(BandwidthResource.bps(10.0)),
+ ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
new LambdaResourceAllocation(LambdaResource.valueOf(1))));
testSerializable(new DefaultLinkResourceAllocations(request, allocations));
}
@@ -378,7 +378,7 @@
@Test
public void testBandwidthConstraint() {
- testSerializable(new BandwidthConstraint(BandwidthResource.bps(1000.0)));
+ testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0))));
}
@Test
diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
index b6ec902..d8af6be 100644
--- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
+++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
@@ -26,6 +26,7 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.Bandwidth;
import org.onlab.util.PositionalParameterStringFormatter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
@@ -55,7 +56,7 @@
@Component(immediate = true)
@Service
public class SimpleLinkResourceStore implements LinkResourceStore {
- private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000);
+ private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000));
private final Logger log = getLogger(getClass());
private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap;
@@ -98,7 +99,8 @@
BandwidthResource bandwidth = DEFAULT_BANDWIDTH;
try {
- bandwidth = BandwidthResource.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH))));
+ bandwidth = new BandwidthResource(
+ Bandwidth.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH)))));
} catch (NumberFormatException e) {
log.debug("No bandwidth annotation on link %s", link);
}
@@ -123,7 +125,7 @@
return (BandwidthResourceAllocation) res;
}
}
- return new BandwidthResourceAllocation(BandwidthResource.bps(0));
+ return new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(0)));
}
/**
@@ -156,7 +158,7 @@
}
freeRes.remove(ba);
freeRes.add(new BandwidthResourceAllocation(
- BandwidthResource.bps(newBandwidth)));
+ new BandwidthResource(Bandwidth.bps(newBandwidth))));
break;
case LAMBDA:
final boolean lambdaAvailable = freeRes.remove(res);
@@ -198,7 +200,7 @@
double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth;
freeRes.remove(ba);
freeRes.add(new BandwidthResourceAllocation(
- BandwidthResource.bps(newBandwidth)));
+ new BandwidthResource(Bandwidth.bps(newBandwidth))));
break;
case LAMBDA:
checkState(freeRes.add(res));
diff --git a/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java b/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
index 2522101..78035c2 100644
--- a/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
+++ b/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
@@ -22,6 +22,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.util.Bandwidth;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -159,7 +160,7 @@
final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes);
assertNotNull(alloc);
- assertEquals(BandwidthResource.mbps(1000.0), alloc.bandwidth());
+ assertEquals(new BandwidthResource(Bandwidth.mbps(1000.0)), alloc.bandwidth());
}
/**
@@ -184,7 +185,7 @@
@Override
public Set<ResourceAllocation> getResourceAllocation(Link link) {
final ResourceAllocation allocation =
- new BandwidthResourceAllocation(BandwidthResource.bps(allocationAmount));
+ new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(allocationAmount)));
final Set<ResourceAllocation> allocations = new HashSet<>();
allocations.add(allocation);
return allocations;