Sho SHIMIZU
Committed by Gerrit Code Review

Avoid double wrap of Bandwidth class

Change-Id: I6bb95beafd55364499df64429c0788153a0b1624
...@@ -39,7 +39,6 @@ import org.onosproject.net.intent.constraint.BandwidthConstraint; ...@@ -39,7 +39,6 @@ import org.onosproject.net.intent.constraint.BandwidthConstraint;
39 import org.onosproject.net.intent.constraint.LambdaConstraint; 39 import org.onosproject.net.intent.constraint.LambdaConstraint;
40 import org.onosproject.net.intent.constraint.LinkTypeConstraint; 40 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
41 import org.onosproject.net.intent.constraint.PartialFailureConstraint; 41 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
42 -import org.onosproject.net.resource.link.BandwidthResource;
43 42
44 import java.util.LinkedList; 43 import java.util.LinkedList;
45 import java.util.List; 44 import java.util.List;
...@@ -365,7 +364,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -365,7 +364,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
365 // Check for a bandwidth specification 364 // Check for a bandwidth specification
366 if (!isNullOrEmpty(bandwidthString)) { 365 if (!isNullOrEmpty(bandwidthString)) {
367 final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString)); 366 final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
368 - constraints.add(new BandwidthConstraint(new BandwidthResource(bandwidth))); 367 + constraints.add(new BandwidthConstraint(bandwidth));
369 } 368 }
370 369
371 // Check for a lambda specification 370 // Check for a lambda specification
......
...@@ -17,9 +17,9 @@ package org.onosproject.net.intent.constraint; ...@@ -17,9 +17,9 @@ package org.onosproject.net.intent.constraint;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 19
20 +import org.onlab.util.Bandwidth;
20 import org.onlab.util.DataRateUnit; 21 import org.onlab.util.DataRateUnit;
21 import org.onosproject.net.Link; 22 import org.onosproject.net.Link;
22 -import org.onosproject.net.resource.link.BandwidthResource;
23 import org.onosproject.net.resource.link.BandwidthResourceRequest; 23 import org.onosproject.net.resource.link.BandwidthResourceRequest;
24 import org.onosproject.net.resource.link.LinkResourceService; 24 import org.onosproject.net.resource.link.LinkResourceService;
25 import org.onosproject.net.resource.ResourceRequest; 25 import org.onosproject.net.resource.ResourceRequest;
...@@ -36,14 +36,14 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -36,14 +36,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
36 @Beta 36 @Beta
37 public final class BandwidthConstraint extends BooleanConstraint { 37 public final class BandwidthConstraint extends BooleanConstraint {
38 38
39 - private final BandwidthResource bandwidth; 39 + private final Bandwidth bandwidth;
40 40
41 /** 41 /**
42 * Creates a new bandwidth constraint. 42 * Creates a new bandwidth constraint.
43 * 43 *
44 * @param bandwidth required bandwidth 44 * @param bandwidth required bandwidth
45 */ 45 */
46 - public BandwidthConstraint(BandwidthResource bandwidth) { 46 + public BandwidthConstraint(Bandwidth bandwidth) {
47 this.bandwidth = checkNotNull(bandwidth, "Bandwidth cannot be null"); 47 this.bandwidth = checkNotNull(bandwidth, "Bandwidth cannot be null");
48 } 48 }
49 49
...@@ -55,7 +55,7 @@ public final class BandwidthConstraint extends BooleanConstraint { ...@@ -55,7 +55,7 @@ public final class BandwidthConstraint extends BooleanConstraint {
55 * @return {@link BandwidthConstraint} instance with given bandwidth requirement 55 * @return {@link BandwidthConstraint} instance with given bandwidth requirement
56 */ 56 */
57 public static BandwidthConstraint of(double v, DataRateUnit unit) { 57 public static BandwidthConstraint of(double v, DataRateUnit unit) {
58 - return new BandwidthConstraint(BandwidthResource.of(v, unit)); 58 + return new BandwidthConstraint(Bandwidth.of(v, unit));
59 } 59 }
60 60
61 // Constructor for serialization 61 // Constructor for serialization
...@@ -68,7 +68,7 @@ public final class BandwidthConstraint extends BooleanConstraint { ...@@ -68,7 +68,7 @@ public final class BandwidthConstraint extends BooleanConstraint {
68 for (ResourceRequest request : resourceService.getAvailableResources(link)) { 68 for (ResourceRequest request : resourceService.getAvailableResources(link)) {
69 if (request.type() == ResourceType.BANDWIDTH) { 69 if (request.type() == ResourceType.BANDWIDTH) {
70 BandwidthResourceRequest brr = (BandwidthResourceRequest) request; 70 BandwidthResourceRequest brr = (BandwidthResourceRequest) request;
71 - if (brr.bandwidth().toDouble() >= bandwidth.toDouble()) { 71 + if (brr.bandwidth().toDouble() >= bandwidth.bps()) {
72 return true; 72 return true;
73 } 73 }
74 } 74 }
...@@ -81,7 +81,7 @@ public final class BandwidthConstraint extends BooleanConstraint { ...@@ -81,7 +81,7 @@ public final class BandwidthConstraint extends BooleanConstraint {
81 * 81 *
82 * @return required bandwidth 82 * @return required bandwidth
83 */ 83 */
84 - public BandwidthResource bandwidth() { 84 + public Bandwidth bandwidth() {
85 return bandwidth; 85 return bandwidth;
86 } 86 }
87 87
......
...@@ -201,7 +201,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { ...@@ -201,7 +201,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest {
201 return addLambdaRequest(); 201 return addLambdaRequest();
202 } else if (constraint instanceof BandwidthConstraint) { 202 } else if (constraint instanceof BandwidthConstraint) {
203 BandwidthConstraint bw = (BandwidthConstraint) constraint; 203 BandwidthConstraint bw = (BandwidthConstraint) constraint;
204 - return addBandwidthRequest(bw.bandwidth().toDouble()); 204 + return addBandwidthRequest(bw.bandwidth().bps());
205 } 205 }
206 return this; 206 return this;
207 } 207 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.net.intent.constraint; ...@@ -18,7 +18,6 @@ package org.onosproject.net.intent.constraint;
18 import org.junit.Test; 18 import org.junit.Test;
19 import org.onlab.util.Bandwidth; 19 import org.onlab.util.Bandwidth;
20 import org.onosproject.net.Link; 20 import org.onosproject.net.Link;
21 -import org.onosproject.net.resource.link.BandwidthResource;
22 import org.onosproject.net.resource.link.LambdaResource; 21 import org.onosproject.net.resource.link.LambdaResource;
23 22
24 import com.google.common.testing.EqualsTester; 23 import com.google.common.testing.EqualsTester;
...@@ -39,21 +38,18 @@ public class ConstraintObjectsTest { ...@@ -39,21 +38,18 @@ public class ConstraintObjectsTest {
39 private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0); 38 private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0);
40 private final Bandwidth bandwidth2 = Bandwidth.bps(200.0); 39 private final Bandwidth bandwidth2 = Bandwidth.bps(200.0);
41 40
42 - final BandwidthConstraint bandwidthConstraint1 = 41 + final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1);
43 - new BandwidthConstraint(new BandwidthResource(bandwidth1)); 42 + final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1);
44 - final BandwidthConstraint bandwidthConstraintSameAs1 = 43 + final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2);
45 - new BandwidthConstraint(new BandwidthResource(sameAsBandwidth1));
46 - final BandwidthConstraint bandwidthConstraint2 =
47 - new BandwidthConstraint(new BandwidthResource(bandwidth2));
48 44
49 /** 45 /**
50 * Checks that the objects were created properly. 46 * Checks that the objects were created properly.
51 */ 47 */
52 @Test 48 @Test
53 public void testBandwidthConstraintCreation() { 49 public void testBandwidthConstraintCreation() {
54 - assertThat(bandwidthConstraint1.bandwidth().toDouble(), is(equalTo(100.0))); 50 + assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0)));
55 - assertThat(bandwidthConstraintSameAs1.bandwidth().toDouble(), is(equalTo(100.0))); 51 + assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0)));
56 - assertThat(bandwidthConstraint2.bandwidth().toDouble(), is(equalTo(200.0))); 52 + assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0)));
57 } 53 }
58 54
59 /** 55 /**
......
...@@ -32,7 +32,6 @@ import org.onosproject.net.intent.constraint.LatencyConstraint; ...@@ -32,7 +32,6 @@ import org.onosproject.net.intent.constraint.LatencyConstraint;
32 import org.onosproject.net.intent.constraint.LinkTypeConstraint; 32 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
33 import org.onosproject.net.intent.constraint.ObstacleConstraint; 33 import org.onosproject.net.intent.constraint.ObstacleConstraint;
34 import org.onosproject.net.intent.constraint.WaypointConstraint; 34 import org.onosproject.net.intent.constraint.WaypointConstraint;
35 -import org.onosproject.net.resource.link.BandwidthResource;
36 import org.onosproject.net.resource.link.LambdaResource; 35 import org.onosproject.net.resource.link.LambdaResource;
37 36
38 import com.fasterxml.jackson.databind.JsonNode; 37 import com.fasterxml.jackson.databind.JsonNode;
...@@ -185,7 +184,7 @@ public final class DecodeConstraintCodecHelper { ...@@ -185,7 +184,7 @@ public final class DecodeConstraintCodecHelper {
185 ConstraintCodec.BANDWIDTH + ConstraintCodec.MISSING_MEMBER_MESSAGE) 184 ConstraintCodec.BANDWIDTH + ConstraintCodec.MISSING_MEMBER_MESSAGE)
186 .asDouble(); 185 .asDouble();
187 186
188 - return new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(bandwidth))); 187 + return new BandwidthConstraint(Bandwidth.bps(bandwidth));
189 } 188 }
190 189
191 /** 190 /**
......
...@@ -128,7 +128,7 @@ public final class EncodeConstraintCodecHelper { ...@@ -128,7 +128,7 @@ public final class EncodeConstraintCodecHelper {
128 final BandwidthConstraint bandwidthConstraint = 128 final BandwidthConstraint bandwidthConstraint =
129 (BandwidthConstraint) constraint; 129 (BandwidthConstraint) constraint;
130 return context.mapper().createObjectNode() 130 return context.mapper().createObjectNode()
131 - .put("bandwidth", bandwidthConstraint.bandwidth().toDouble()); 131 + .put("bandwidth", bandwidthConstraint.bandwidth().bps());
132 } 132 }
133 133
134 /** 134 /**
......
...@@ -134,7 +134,7 @@ public class ConstraintCodecTest { ...@@ -134,7 +134,7 @@ public class ConstraintCodecTest {
134 assertThat(constraint, instanceOf(BandwidthConstraint.class)); 134 assertThat(constraint, instanceOf(BandwidthConstraint.class));
135 135
136 BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint; 136 BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint;
137 - assertThat(bandwidthConstraint.bandwidth().toDouble(), is(345.678D)); 137 + assertThat(bandwidthConstraint.bandwidth().bps(), is(345.678D));
138 } 138 }
139 139
140 /** 140 /**
......
...@@ -63,7 +63,6 @@ import org.onosproject.net.intent.constraint.LambdaConstraint; ...@@ -63,7 +63,6 @@ import org.onosproject.net.intent.constraint.LambdaConstraint;
63 import org.onosproject.net.intent.constraint.LatencyConstraint; 63 import org.onosproject.net.intent.constraint.LatencyConstraint;
64 import org.onosproject.net.intent.constraint.ObstacleConstraint; 64 import org.onosproject.net.intent.constraint.ObstacleConstraint;
65 import org.onosproject.net.intent.constraint.WaypointConstraint; 65 import org.onosproject.net.intent.constraint.WaypointConstraint;
66 -import org.onosproject.net.resource.link.BandwidthResource;
67 import org.onosproject.net.resource.link.LambdaResource; 66 import org.onosproject.net.resource.link.LambdaResource;
68 67
69 import com.fasterxml.jackson.databind.JsonNode; 68 import com.fasterxml.jackson.databind.JsonNode;
...@@ -181,7 +180,7 @@ public class IntentCodecTest extends AbstractIntentTest { ...@@ -181,7 +180,7 @@ public class IntentCodecTest extends AbstractIntentTest {
181 180
182 final List<Constraint> constraints = 181 final List<Constraint> constraints =
183 ImmutableList.of( 182 ImmutableList.of(
184 - new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1.0))), 183 + new BandwidthConstraint(Bandwidth.bps(1.0)),
185 new LambdaConstraint(LambdaResource.valueOf(3)), 184 new LambdaConstraint(LambdaResource.valueOf(3)),
186 new AnnotationConstraint("key", 33.0), 185 new AnnotationConstraint("key", 33.0),
187 new AsymmetricPathConstraint(), 186 new AsymmetricPathConstraint(),
......
...@@ -141,7 +141,7 @@ public final class IntentJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> ...@@ -141,7 +141,7 @@ public final class IntentJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode>
141 final JsonNode bandwidthJson = constraintJson.get("bandwidth"); 141 final JsonNode bandwidthJson = constraintJson.get("bandwidth");
142 return bandwidthJson != null 142 return bandwidthJson != null
143 && constraintJson.get("bandwidth").asDouble() 143 && constraintJson.get("bandwidth").asDouble()
144 - == bandwidthConstraint.bandwidth().toDouble(); 144 + == bandwidthConstraint.bandwidth().bps();
145 } 145 }
146 146
147 /** 147 /**
......
...@@ -34,7 +34,6 @@ import org.onosproject.net.intent.PointToPointIntent; ...@@ -34,7 +34,6 @@ import org.onosproject.net.intent.PointToPointIntent;
34 import org.onosproject.net.intent.constraint.BandwidthConstraint; 34 import org.onosproject.net.intent.constraint.BandwidthConstraint;
35 import org.onosproject.net.intent.constraint.LambdaConstraint; 35 import org.onosproject.net.intent.constraint.LambdaConstraint;
36 import org.onosproject.net.intent.impl.PathNotFoundException; 36 import org.onosproject.net.intent.impl.PathNotFoundException;
37 -import org.onosproject.net.resource.link.BandwidthResource;
38 import org.onosproject.net.resource.link.LambdaResource; 37 import org.onosproject.net.resource.link.LambdaResource;
39 import org.onosproject.net.resource.link.LinkResourceService; 38 import org.onosproject.net.resource.link.LinkResourceService;
40 39
...@@ -229,7 +228,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -229,7 +228,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
229 final LinkResourceService resourceService = 228 final LinkResourceService resourceService =
230 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); 229 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
231 final List<Constraint> constraints = 230 final List<Constraint> constraints =
232 - Collections.singletonList(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0)))); 231 + Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0)));
233 232
234 final PointToPointIntent intent = makeIntent("s1", "s3", constraints); 233 final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
235 234
...@@ -251,7 +250,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -251,7 +250,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
251 final LinkResourceService resourceService = 250 final LinkResourceService resourceService =
252 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); 251 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
253 final List<Constraint> constraints = 252 final List<Constraint> constraints =
254 - Collections.singletonList(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0)))); 253 + Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0)));
255 254
256 try { 255 try {
257 final PointToPointIntent intent = makeIntent("s1", "s3", constraints); 256 final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
......
...@@ -400,7 +400,7 @@ public class KryoSerializerTest { ...@@ -400,7 +400,7 @@ public class KryoSerializerTest {
400 400
401 @Test 401 @Test
402 public void testBandwidthConstraint() { 402 public void testBandwidthConstraint() {
403 - testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0)))); 403 + testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
404 } 404 }
405 405
406 @Test 406 @Test
......