Sho SHIMIZU

Populate Bandwidth with BandwidthResource

Change-Id: I7412c0c8141a8e22c2b157ee81989a79939c2299
...@@ -15,27 +15,31 @@ ...@@ -15,27 +15,31 @@
15 */ 15 */
16 package org.onosproject.net.resource; 16 package org.onosproject.net.resource;
17 17
18 +import org.onlab.util.Bandwidth;
19 +
18 import java.util.Objects; 20 import java.util.Objects;
19 21
22 +import static com.google.common.base.Preconditions.checkNotNull;
23 +
20 /** 24 /**
21 * Representation of bandwidth resource in bps. 25 * Representation of bandwidth resource in bps.
22 */ 26 */
23 public final class BandwidthResource extends LinkResource { 27 public final class BandwidthResource extends LinkResource {
24 28
25 - private final double bandwidth; 29 + private final Bandwidth bandwidth;
26 30
27 /** 31 /**
28 * Creates a new instance with given bandwidth. 32 * Creates a new instance with given bandwidth.
29 * 33 *
30 * @param bandwidth bandwidth value to be assigned 34 * @param bandwidth bandwidth value to be assigned
31 */ 35 */
32 - private BandwidthResource(double bandwidth) { 36 + private BandwidthResource(Bandwidth bandwidth) {
33 - this.bandwidth = bandwidth; 37 + this.bandwidth = checkNotNull(bandwidth);
34 } 38 }
35 39
36 // Constructor for serialization 40 // Constructor for serialization
37 private BandwidthResource() { 41 private BandwidthResource() {
38 - this.bandwidth = 0; 42 + this.bandwidth = null;
39 } 43 }
40 44
41 /** 45 /**
...@@ -49,6 +53,10 @@ public final class BandwidthResource extends LinkResource { ...@@ -49,6 +53,10 @@ public final class BandwidthResource extends LinkResource {
49 return bps(bandwidth); 53 return bps(bandwidth);
50 } 54 }
51 55
56 + public static BandwidthResource from(Bandwidth bandwidth) {
57 + return new BandwidthResource(bandwidth);
58 + }
59 +
52 /** 60 /**
53 * Creates a new instance with given bandwidth in bps. 61 * Creates a new instance with given bandwidth in bps.
54 * 62 *
...@@ -56,7 +64,7 @@ public final class BandwidthResource extends LinkResource { ...@@ -56,7 +64,7 @@ public final class BandwidthResource extends LinkResource {
56 * @return {@link BandwidthResource} instance with given bandwidth 64 * @return {@link BandwidthResource} instance with given bandwidth
57 */ 65 */
58 public static BandwidthResource bps(double bps) { 66 public static BandwidthResource bps(double bps) {
59 - return new BandwidthResource(bps); 67 + return from(Bandwidth.bps(bps));
60 } 68 }
61 69
62 /** 70 /**
...@@ -66,7 +74,7 @@ public final class BandwidthResource extends LinkResource { ...@@ -66,7 +74,7 @@ public final class BandwidthResource extends LinkResource {
66 * @return {@link BandwidthResource} instance with given bandwidth 74 * @return {@link BandwidthResource} instance with given bandwidth
67 */ 75 */
68 public static BandwidthResource kbps(double kbps) { 76 public static BandwidthResource kbps(double kbps) {
69 - return new BandwidthResource(kbps * 1_000L); 77 + return from(Bandwidth.kbps(kbps));
70 } 78 }
71 79
72 /** 80 /**
...@@ -76,7 +84,7 @@ public final class BandwidthResource extends LinkResource { ...@@ -76,7 +84,7 @@ public final class BandwidthResource extends LinkResource {
76 * @return {@link BandwidthResource} instance with given bandwidth 84 * @return {@link BandwidthResource} instance with given bandwidth
77 */ 85 */
78 public static BandwidthResource mbps(double mbps) { 86 public static BandwidthResource mbps(double mbps) {
79 - return new BandwidthResource(mbps * 1_000_000L); 87 + return from(Bandwidth.mbps(mbps));
80 } 88 }
81 89
82 /** 90 /**
...@@ -86,7 +94,7 @@ public final class BandwidthResource extends LinkResource { ...@@ -86,7 +94,7 @@ public final class BandwidthResource extends LinkResource {
86 * @return {@link BandwidthResource} instance with given bandwidth 94 * @return {@link BandwidthResource} instance with given bandwidth
87 */ 95 */
88 public static BandwidthResource gbps(double gbps) { 96 public static BandwidthResource gbps(double gbps) {
89 - return new BandwidthResource(gbps * 1_000_000_000L); 97 + return from(Bandwidth.gbps(gbps));
90 } 98 }
91 99
92 /** 100 /**
...@@ -95,7 +103,7 @@ public final class BandwidthResource extends LinkResource { ...@@ -95,7 +103,7 @@ public final class BandwidthResource extends LinkResource {
95 * @return bandwidth as a double value 103 * @return bandwidth as a double value
96 */ 104 */
97 public double toDouble() { 105 public double toDouble() {
98 - return bandwidth; 106 + return bandwidth.bps();
99 } 107 }
100 108
101 @Override 109 @Override
......