Refactor connectivity intent creation to use builders

- Each connectivity intent now has only one constructor
- Intent constructors are now private for leaf classes and
  protected for classes that can be derived from
- Each intent class has a Builder class that accumulates
  parameters for intent creation
- Each intent class has a public static builder() method
  to create a builder
- Each Builder class has a build() method to create the
  intent from the accumulated parameters
- Added keys to a few intent types that were missing them
- Tightened up usage of checkNotNull(), taking advantage of
  the return value to save some lines of code
- Modified callers to use the builders instead of directly
  calling the constructors

Change-Id: I713185d5ecbadbf51f87ef7f68fec41102106c78
diff --git a/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java
index c476144..31d6c4d 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java
@@ -27,7 +27,6 @@
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.is;
 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-import static org.onosproject.net.NetTestTools.APP_ID;
 import static org.onosproject.net.NetTestTools.hid;
 
 /**
@@ -43,7 +42,13 @@
     private static final ApplicationId APPID = new TestApplicationId("foo");
 
     private HostToHostIntent makeHostToHost(HostId one, HostId two) {
-        return new HostToHostIntent(APPID, one, two, selector, treatment);
+        return HostToHostIntent.builder()
+                .appId(APPID)
+                .one(one)
+                .two(two)
+                .selector(selector)
+                .treatment(treatment)
+                .build();
     }
 
     /**
@@ -75,17 +80,21 @@
      */
     @Test
     public void testEquals() {
-        final HostToHostIntent intent1 = new HostToHostIntent(APP_ID,
-                id1,
-                id2,
-                selector,
-                treatment);
+        final HostToHostIntent intent1 = HostToHostIntent.builder()
+                .appId(APPID)
+                .one(id1)
+                .two(id2)
+                .selector(selector)
+                .treatment(treatment)
+                .build();
 
-        final HostToHostIntent intent2 = new HostToHostIntent(APP_ID,
-                id2,
-                id3,
-                selector,
-                treatment);
+        final HostToHostIntent intent2 = HostToHostIntent.builder()
+                .appId(APPID)
+                .one(id2)
+                .two(id3)
+                .selector(selector)
+                .treatment(treatment)
+                .build();
 
         new EqualsTester()
                 .addEqualityGroup(intent1)
@@ -95,11 +104,23 @@
 
     @Override
     protected Intent createOne() {
-        return new HostToHostIntent(APP_ID, id1, id2, selector, treatment);
+        return HostToHostIntent.builder()
+                .appId(APPID)
+                .one(id1)
+                .two(id2)
+                .selector(selector)
+                .treatment(treatment)
+                .build();
     }
 
     @Override
     protected Intent createAnother() {
-        return new HostToHostIntent(APP_ID, id1, id3, selector, treatment);
+        return HostToHostIntent.builder()
+                .appId(APPID)
+                .one(id1)
+                .two(id3)
+                .selector(selector)
+                .treatment(treatment)
+                .build();
     }
 }
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 dca1906..4ae09fb 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
@@ -419,12 +419,13 @@
         private final Long number;
 
         public MockIntent(Long number) {
-            super(NetTestTools.APP_ID, Collections.emptyList());
+            super(NetTestTools.APP_ID, null, Collections.emptyList(),
+                    Intent.DEFAULT_INTENT_PRIORITY);
             this.number = number;
         }
 
         public MockIntent(Long number, Collection<NetworkResource> resources) {
-            super(NetTestTools.APP_ID, resources);
+            super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY);
             this.number = number;
         }
 
diff --git a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
index a9ae782..4263531 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
@@ -67,22 +67,26 @@
         final HashSet<Link> links1 = new HashSet<>();
         links1.add(link("src", 1, "dst", 2));
         final LinkCollectionIntent collectionIntent1 =
-                new LinkCollectionIntent(APP_ID,
-                        selector,
-                        treatment,
-                        links1,
-                        ingress,
-                        egress);
+                LinkCollectionIntent.builder()
+                        .appId(APP_ID)
+                        .selector(selector)
+                        .treatment(treatment)
+                        .links(links1)
+                        .ingressPoints(ImmutableSet.of(ingress))
+                        .egressPoints(ImmutableSet.of(egress))
+                        .build();
 
         final HashSet<Link> links2 = new HashSet<>();
         links2.add(link("src", 1, "dst", 3));
         final LinkCollectionIntent collectionIntent2 =
-                new LinkCollectionIntent(APP_ID,
-                        selector,
-                        treatment,
-                        links2,
-                        ingress,
-                        egress);
+                LinkCollectionIntent.builder()
+                        .appId(APP_ID)
+                        .selector(selector)
+                        .treatment(treatment)
+                        .links(links2)
+                        .ingressPoints(ImmutableSet.of(ingress))
+                        .egressPoints(ImmutableSet.of(egress))
+                        .build();
 
         new EqualsTester()
                 .addEqualityGroup(collectionIntent1)
@@ -98,12 +102,14 @@
         final HashSet<Link> links1 = new HashSet<>();
         links1.add(link("src", 1, "dst", 2));
         final LinkCollectionIntent collectionIntent =
-                new LinkCollectionIntent(APP_ID,
-                        selector,
-                        treatment,
-                        links1,
-                        ingress,
-                        egress);
+                LinkCollectionIntent.builder()
+                        .appId(APP_ID)
+                        .selector(selector)
+                        .treatment(treatment)
+                        .links(links1)
+                        .ingressPoints(ImmutableSet.of(ingress))
+                        .egressPoints(ImmutableSet.of(egress))
+                        .build();
 
         final Set<Link> createdLinks = collectionIntent.links();
         assertThat(createdLinks, hasSize(1));
@@ -128,14 +134,16 @@
         links1.add(link("src", 1, "dst", 2));
         constraints.add(new LambdaConstraint(Lambda.valueOf(23)));
         final LinkCollectionIntent collectionIntent =
-                new LinkCollectionIntent(APP_ID,
-                        selector,
-                        treatment,
-                        links1,
-                        ingress,
-                        egress,
-                        constraints,
-                        8888);
+                LinkCollectionIntent.builder()
+                        .appId(APP_ID)
+                        .selector(selector)
+                        .treatment(treatment)
+                        .links(links1)
+                        .ingressPoints(ImmutableSet.of(ingress))
+                        .egressPoints(ImmutableSet.of(egress))
+                        .constraints(constraints)
+                        .priority(8888)
+                        .build();
 
         final Set<Link> createdLinks = collectionIntent.links();
         assertThat(createdLinks, hasSize(1));
@@ -175,23 +183,27 @@
     protected Intent createOne() {
         HashSet<Link> links1 = new HashSet<>();
         links1.add(link("src", 1, "dst", 2));
-        return new LinkCollectionIntent(APP_ID,
-                                        selector,
-                                        treatment,
-                                        links1,
-                                        ingress,
-                                        egress);
+        return LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .links(links1)
+                .ingressPoints(ImmutableSet.of(ingress))
+                .egressPoints(ImmutableSet.of(egress))
+                .build();
     }
 
     @Override
     protected Intent createAnother() {
         HashSet<Link> links2 = new HashSet<>();
         links2.add(link("src", 1, "dst", 3));
-        return new LinkCollectionIntent(APP_ID,
-                                        selector,
-                                        treatment,
-                                        links2,
-                                        ingress,
-                                        egress);
+        return LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .links(links2)
+                .ingressPoints(ImmutableSet.of(ingress))
+                .egressPoints(ImmutableSet.of(egress))
+                .build();
     }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java
index cab6a8d..2aac906 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java
@@ -44,11 +44,23 @@
 
     @Override
     protected MultiPointToSinglePointIntent createOne() {
-        return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS1, P2);
+        return MultiPointToSinglePointIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .ingressPoints(PS1)
+                .egressPoint(P2)
+                .build();
     }
 
     @Override
     protected MultiPointToSinglePointIntent createAnother() {
-        return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS2, P1);
+        return MultiPointToSinglePointIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .ingressPoints(PS2)
+                .egressPoint(P1)
+                .build();
     }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
index 6db1a35..2149b26 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
@@ -15,6 +15,8 @@
  */
 package org.onosproject.net.intent;
 
+import java.util.Arrays;
+
 import org.junit.Test;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultLink;
@@ -25,8 +27,6 @@
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.provider.ProviderId;
 
-import java.util.Arrays;
-
 import static org.junit.Assert.assertEquals;
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.onosproject.net.Link.Type.DIRECT;
@@ -65,12 +65,22 @@
 
     @Override
     protected PathIntent createOne() {
-        return new PathIntent(APPID, MATCH, NOP, PATH1);
+        return PathIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .path(PATH1)
+                .build();
     }
 
     @Override
     protected PathIntent createAnother() {
-        return new PathIntent(APPID, MATCH, NOP, PATH2);
+        return PathIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .path(PATH2)
+                .build();
     }
 
     /**
@@ -79,7 +89,12 @@
      */
     @Test(expected = IllegalArgumentException.class)
     public void testRaiseExceptionWhenSameDevices() {
-        new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1), cost));
+        PathIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .path(new DefaultPath(provider1, Arrays.asList(link1), cost))
+                .build();
     }
 
     /**
@@ -88,7 +103,12 @@
      */
     @Test(expected = IllegalArgumentException.class)
     public void testRaiseExceptionWhenDifferentDevice() {
-        new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1, link2), cost));
+        PathIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost))
+                .build();
     }
 
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java
index f0f8ebf..325c4f2 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java
@@ -44,11 +44,23 @@
 
     @Override
     protected SinglePointToMultiPointIntent createOne() {
-        return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P1, PS2);
+        return SinglePointToMultiPointIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .ingressPoint(P1)
+                .egressPoints(PS2)
+                .build();
     }
 
     @Override
     protected SinglePointToMultiPointIntent createAnother() {
-        return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P2, PS1);
+        return SinglePointToMultiPointIntent.builder()
+                .appId(APPID)
+                .selector(MATCH)
+                .treatment(NOP)
+                .ingressPoint(P2)
+                .egressPoints(PS1)
+                .build();
     }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
index 32e5c90..bf3176d 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java
@@ -32,7 +32,8 @@
      * @param value intent ID
      */
     public TestInstallableIntent(int value) { // FIXME
-        super(new TestApplicationId("foo"), Collections.emptyList());
+        super(new TestApplicationId("foo"), null, Collections.emptyList(),
+                Intent.DEFAULT_INTENT_PRIORITY);
         this.value = value;
     }
 
diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
index b3a8679..af3ea49 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java
@@ -32,7 +32,8 @@
      * @param value intent ID
      */
     public TestIntent(int value) { // FIXME
-        super(new TestApplicationId("foo"), Collections.emptyList());
+        super(new TestApplicationId("foo"), null, Collections.emptyList(),
+                Intent.DEFAULT_INTENT_PRIORITY);
         this.value = value;
     }