Yuta HIGUCHI
Committed by Gerrit Code Review

Minor changes around ProtectionConstraint

- use factory
- implement toString

Change-Id: Ic30b2d3a7c2f6c65fac9b0971291d82af8ec23d7
...@@ -25,7 +25,7 @@ import org.onosproject.net.intent.Constraint; ...@@ -25,7 +25,7 @@ import org.onosproject.net.intent.Constraint;
25 import org.onosproject.net.intent.Intent; 25 import org.onosproject.net.intent.Intent;
26 import org.onosproject.net.intent.IntentService; 26 import org.onosproject.net.intent.IntentService;
27 import org.onosproject.net.intent.PointToPointIntent; 27 import org.onosproject.net.intent.PointToPointIntent;
28 -import org.onosproject.net.intent.constraint.ProtectionConstraint; 28 +import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection;
29 29
30 import java.util.List; 30 import java.util.List;
31 31
...@@ -65,7 +65,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { ...@@ -65,7 +65,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
65 65
66 List<Constraint> constraints = buildConstraints(); 66 List<Constraint> constraints = buildConstraints();
67 if (backup) { 67 if (backup) {
68 - constraints.add(new ProtectionConstraint()); 68 + constraints.add(protection());
69 } 69 }
70 70
71 Intent intent = PointToPointIntent.builder() 71 Intent intent = PointToPointIntent.builder()
......
...@@ -29,6 +29,8 @@ import org.onosproject.net.intent.ResourceContext; ...@@ -29,6 +29,8 @@ import org.onosproject.net.intent.ResourceContext;
29 */ 29 */
30 @Beta 30 @Beta
31 public class ProtectionConstraint implements Constraint { 31 public class ProtectionConstraint implements Constraint {
32 + private static final ProtectionConstraint PROTECTION_CONSTRAINT = new ProtectionConstraint();
33 +
32 // doesn't use LinkResourceService 34 // doesn't use LinkResourceService
33 @Override 35 @Override
34 public double cost(Link link, ResourceContext context) { 36 public double cost(Link link, ResourceContext context) {
...@@ -55,4 +57,21 @@ public class ProtectionConstraint implements Constraint { ...@@ -55,4 +57,21 @@ public class ProtectionConstraint implements Constraint {
55 } 57 }
56 return false; 58 return false;
57 } 59 }
60 +
61 + /**
62 + * Returns protection constraint.
63 + *
64 + * @return
65 + */
66 + public static ProtectionConstraint protection() {
67 + return PROTECTION_CONSTRAINT;
68 + }
69 +
70 + protected ProtectionConstraint() {
71 + }
72 +
73 + @Override
74 + public String toString() {
75 + return "Protection";
76 + }
58 } 77 }
......