Inline static factory methods in BandwidthResource

Change-Id: I8ac7fbaea5c81c9558f88f6ac88bcf581466d073
diff --git a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
index 387ba44..b17d04c 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
@@ -24,6 +24,7 @@
 import org.apache.karaf.shell.commands.Option;
 import org.onlab.packet.Ip6Address;
 import org.onlab.packet.IpAddress;
+import org.onlab.util.Bandwidth;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
@@ -306,8 +307,8 @@
 
         // Check for a bandwidth specification
         if (!isNullOrEmpty(bandwidthString)) {
-            final double bandwidthValue = Double.parseDouble(bandwidthString);
-            constraints.add(new BandwidthConstraint(BandwidthResource.bps(bandwidthValue)));
+            final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
+            constraints.add(new BandwidthConstraint(new BandwidthResource(bandwidth)));
         }
 
         // Check for a lambda specification
diff --git a/core/api/src/main/java/org/onosproject/net/resource/BandwidthResource.java b/core/api/src/main/java/org/onosproject/net/resource/BandwidthResource.java
index 0f39198..3c8ebea 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/BandwidthResource.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/BandwidthResource.java
@@ -33,7 +33,7 @@
      *
      * @param bandwidth bandwidth value to be assigned
      */
-    private BandwidthResource(Bandwidth bandwidth) {
+    public BandwidthResource(Bandwidth bandwidth) {
         this.bandwidth = checkNotNull(bandwidth);
     }
 
@@ -43,61 +43,6 @@
     }
 
     /**
-     * Creates a new instance with given bandwidth in bps.
-     *
-     * @param bandwidth bandwidth value to be assigned
-     * @return {@link BandwidthResource} instance with given bandwidth
-     */
-    @Deprecated
-    public static BandwidthResource valueOf(double bandwidth) {
-        return bps(bandwidth);
-    }
-
-    public static BandwidthResource from(Bandwidth bandwidth) {
-        return new BandwidthResource(bandwidth);
-    }
-
-    /**
-     * Creates a new instance with given bandwidth in bps.
-     *
-     * @param bps bandwidth value to be assigned
-     * @return {@link BandwidthResource} instance with given bandwidth
-     */
-    public static BandwidthResource bps(double bps) {
-        return from(Bandwidth.bps(bps));
-    }
-
-    /**
-     * Creates a new instance with given bandwidth in Kbps.
-     *
-     * @param kbps bandwidth value to be assigned
-     * @return {@link BandwidthResource} instance with given bandwidth
-     */
-    public static BandwidthResource kbps(double kbps) {
-        return from(Bandwidth.kbps(kbps));
-    }
-
-    /**
-     * Creates a new instance with given bandwidth in Mbps.
-     *
-     * @param mbps bandwidth value to be assigned
-     * @return {@link BandwidthResource} instance with given bandwidth
-     */
-    public static BandwidthResource mbps(double mbps) {
-        return from(Bandwidth.mbps(mbps));
-    }
-
-    /**
-     * Creates a new instance with given bandwidth in Gbps.
-     *
-     * @param gbps bandwidth value to be assigned
-     * @return {@link BandwidthResource} instance with given bandwidth
-     */
-    public static BandwidthResource gbps(double gbps) {
-        return from(Bandwidth.gbps(gbps));
-    }
-
-    /**
      * Returns bandwidth as a double value.
      *
      * @return bandwidth as a double value
diff --git a/core/api/src/main/java/org/onosproject/net/resource/DefaultLinkResourceRequest.java b/core/api/src/main/java/org/onosproject/net/resource/DefaultLinkResourceRequest.java
index 1ec1fc4..8d08e3b 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/DefaultLinkResourceRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/DefaultLinkResourceRequest.java
@@ -20,6 +20,7 @@
 import java.util.Set;
 import java.util.Objects;
 
+import org.onlab.util.Bandwidth;
 import org.onosproject.net.Link;
 import org.onosproject.net.intent.Constraint;
 import org.onosproject.net.intent.IntentId;
@@ -137,7 +138,7 @@
          */
         @Override
         public Builder addBandwidthRequest(double bandwidth) {
-            resources.add(new BandwidthResourceRequest(BandwidthResource.bps(bandwidth)));
+            resources.add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth))));
             return this;
         }
 
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index 37bea8d..47faf4a 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -18,6 +18,7 @@
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableSet;
 
+import org.onlab.util.Bandwidth;
 import org.onosproject.core.DefaultGroupId;
 import org.onosproject.core.GroupId;
 import org.onosproject.net.DeviceId;
@@ -302,7 +303,7 @@
             final List<ResourceRequest> result = new LinkedList<>();
             if (availableBandwidth > 0.0) {
                 result.add(new BandwidthResourceRequest(
-                        BandwidthResource.bps(availableBandwidth)));
+                        new BandwidthResource(Bandwidth.bps(availableBandwidth))));
             }
             if (availableLambda > 0) {
                 result.add(new LambdaResourceRequest());
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
index 5505e13..cc29a25 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent.constraint;
 
 import org.junit.Test;
+import org.onlab.util.Bandwidth;
 import org.onosproject.net.Link;
 import org.onosproject.net.resource.BandwidthResource;
 import org.onosproject.net.resource.LambdaResource;
@@ -34,12 +35,16 @@
 
     // Bandwidth Constraint
 
+    private final Bandwidth bandwidth1 = Bandwidth.bps(100.0);
+    private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0);
+    private final Bandwidth bandwidth2 = Bandwidth.bps(200.0);
+
     final BandwidthConstraint bandwidthConstraint1 =
-            new BandwidthConstraint(BandwidthResource.bps(100.0));
+            new BandwidthConstraint(new BandwidthResource(bandwidth1));
     final BandwidthConstraint bandwidthConstraintSameAs1 =
-            new BandwidthConstraint(BandwidthResource.bps(100.0));
+            new BandwidthConstraint(new BandwidthResource(sameAsBandwidth1));
     final BandwidthConstraint bandwidthConstraint2 =
-            new BandwidthConstraint(BandwidthResource.bps(200.0));
+            new BandwidthConstraint(new BandwidthResource(bandwidth2));
 
     /**
      * Checks that the objects were created properly.
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
index b76ae83..0318b8f 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
@@ -22,6 +22,7 @@
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.MplsLabel;
+import org.onlab.util.Bandwidth;
 import org.onosproject.codec.CodecContext;
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.core.ApplicationId;
@@ -145,7 +146,7 @@
 
         final List<Constraint> constraints =
                 ImmutableList.of(
-                    new BandwidthConstraint(BandwidthResource.bps(1.0)),
+                    new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1.0))),
                     new LambdaConstraint(LambdaResource.valueOf(3)),
                     new AnnotationConstraint("key", 33.0),
                     new AsymmetricPathConstraint(),
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
index 20df3f1..00fcf44 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -17,6 +17,7 @@
 
 import org.hamcrest.Matchers;
 import org.junit.Test;
+import org.onlab.util.Bandwidth;
 import org.onosproject.TestApplicationId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.ConnectPoint;
@@ -227,7 +228,8 @@
 
         final LinkResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
-        final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(BandwidthResource.bps(100.0)));
+        final List<Constraint> constraints = Arrays.asList(
+                new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
 
         final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
 
@@ -248,7 +250,8 @@
 
         final LinkResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
-        final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(BandwidthResource.bps(100.0)));
+        final List<Constraint> constraints = Arrays.asList(
+                new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
 
         try {
             final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
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;