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/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
index 5481007..64c963b 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
@@ -502,7 +502,8 @@
     public void intentWithoutCompiler() {
         class IntentNoCompiler extends Intent {
             IntentNoCompiler() {
-                super(APPID, Collections.emptyList());
+                super(APPID, null, Collections.emptyList(),
+                        Intent.DEFAULT_INTENT_PRIORITY);
             }
         }
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
index b154d22..be9ab66 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
@@ -90,8 +90,13 @@
      * @return HostToHostIntent for the two hosts
      */
     private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
-        return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString),
-                                    selector, treatment);
+        return HostToHostIntent.builder()
+                .appId(APPID)
+                .one(hid(oneIdString))
+                .two(hid(twoIdString))
+                .selector(selector)
+                .treatment(treatment)
+                .build();
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
index 4890e03..76b26f4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
@@ -55,11 +55,14 @@
     private MplsIntent makeIntent(String ingressIdString,  Optional<MplsLabel> ingressLabel,
                                           String egressIdString, Optional<MplsLabel> egressLabel) {
 
-        return new MplsIntent(APPID, selector, treatment,
-                                      connectPoint(ingressIdString, 1),
-                                      ingressLabel,
-                                      connectPoint(egressIdString, 1),
-                                      egressLabel);
+        return MplsIntent.builder()
+                .appId(APPID)
+                .selector(selector)
+                .treatment(treatment)
+                .ingressPoint(connectPoint(ingressIdString, 1))
+                .ingressLabel(ingressLabel)
+                .egressPoint(connectPoint(egressIdString, 1))
+                .egressLabel(egressLabel).build();
     }
     /**
      * Creates a compiler for HostToHost intents.
@@ -157,7 +160,15 @@
     public void testSameSwitchDifferentPortsIntentCompilation() {
         ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
         ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2));
-        MplsIntent intent = new MplsIntent(APP_ID, selector, treatment, src, Optional.empty(), dst, Optional.empty());
+        MplsIntent intent = MplsIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .ingressPoint(src)
+                .ingressLabel(Optional.empty())
+                .egressPoint(dst)
+                .egressLabel(Optional.empty())
+                .build();
 
         String[] hops = {"1"};
         MplsIntentCompiler sut = makeCompiler(hops);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
index bbc7ad1..eb6be57 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -104,8 +104,13 @@
             ingressPoints.add(connectPoint(ingressId, 1));
         }
 
-        return new MultiPointToSinglePointIntent(APPID, selector, treatment,
-                                                 ingressPoints, egressPoint);
+        return MultiPointToSinglePointIntent.builder()
+                .appId(APPID)
+                .selector(selector)
+                .treatment(treatment)
+                .ingressPoints(ingressPoints)
+                .egressPoint(egressPoint)
+                .build();
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java
index 9f88fa6..00ebedf 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java
@@ -56,7 +56,14 @@
         installer.coreService = testCoreService;
         installer.intentManager =
                 new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class);
-        intent = new LinkCollectionIntent(APP_ID, selector, treatment, links, d1p1, d3p1);
+        intent = LinkCollectionIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .links(links)
+                .ingressPoints(ImmutableSet.of(d1p1))
+                .egressPoints(ImmutableSet.of(d3p1))
+                .build();
     }
 
     private FlowRuleOperation findOperation(Collection<FlowRuleOperation> ops,
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java
index 8001eed..e88947c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java
@@ -31,8 +31,6 @@
 import org.onosproject.net.intent.MplsPathIntent;
 import org.onosproject.store.trivial.impl.SimpleLinkStore;
 
-import com.google.common.collect.ImmutableList;
-
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.notNullValue;
@@ -70,12 +68,15 @@
         installer.linkStore = new SimpleLinkStore();
         installer.resourceService = new IntentTestsMocks.MockResourceService();
 
-        intent = new MplsPathIntent(APP_ID, selector, treatment,
-                new DefaultPath(PID, links, hops),
-                ingressLabel,
-                egressLabel,
-                ImmutableList.of(),
-                55);
+        intent = MplsPathIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .path(new DefaultPath(PID, links, hops))
+                .ingressLabel(ingressLabel)
+                .egressLabel(egressLabel)
+                .priority(55)
+                .build();
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
index d0bb843..6e7606d 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
@@ -73,8 +73,14 @@
 
     private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) {
         int hops = links.size() - 1;
-        return new PathIntent(APP_ID, selector, treatment,
-                              new DefaultPath(PID, links, hops), constraints, 333);
+        return PathIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .path(new DefaultPath(PID, links, hops))
+                .constraints(constraints)
+                .priority(333)
+                .build();
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
index 695f115..9bbd16c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
@@ -27,8 +27,6 @@
 import org.onosproject.net.flow.FlowRuleOperation;
 import org.onosproject.net.intent.PathIntent;
 
-import com.google.common.collect.ImmutableList;
-
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.notNullValue;
@@ -61,9 +59,13 @@
         installer = new PathIntentInstaller();
         installer.coreService = testCoreService;
         installer.intentManager = new MockIntentManager(PathIntent.class);
-        intent = new PathIntent(APP_ID, selector, treatment,
-                new DefaultPath(PID, links, hops), ImmutableList.of(),
-                77);
+        intent = PathIntent.builder()
+                .appId(APP_ID)
+                .selector(selector)
+                .treatment(treatment)
+                .path(new DefaultPath(PID, links, hops))
+                .priority(77)
+                .build();
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
index d450812..a968e4e 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
@@ -97,7 +97,12 @@
                 .ingressPoint(cp1)
                 .egressPoint(cp3)
                 .build();
-        compiled = new PathIntent(appId, selector, treatment, path);
+        compiled = PathIntent.builder()
+                .appId(appId)
+                .selector(selector)
+                .treatment(treatment)
+                .path(path)
+                .build();
     }
 
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java
index 678bd2d..1938425 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java
@@ -98,7 +98,12 @@
                 .ingressPoint(cp1)
                 .egressPoint(cp3)
                 .build();
-        compiled = new PathIntent(appId, selector, treatment, path);
+        compiled = PathIntent.builder()
+                .appId(appId)
+                .selector(selector)
+                .treatment(treatment)
+                .path(path)
+                .build();
     }
 
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java
index b7d063f..8d4b334 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java
@@ -98,7 +98,12 @@
                 .ingressPoint(cp1)
                 .egressPoint(cp3)
                 .build();
-        compiled = new PathIntent(appId, selector, treatment, path);
+        compiled = PathIntent.builder()
+                .appId(appId)
+                .selector(selector)
+                .treatment(treatment)
+                .path(path)
+                .build();
     }
 
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java
index 19c3f6f..5d40516 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java
@@ -99,7 +99,12 @@
                 .ingressPoint(cp1)
                 .egressPoint(cp3)
                 .build();
-        compiled = new PathIntent(appId, selector, treatment, path);
+        compiled = PathIntent.builder()
+                .appId(appId)
+                .selector(selector)
+                .treatment(treatment)
+                .path(path)
+                .build();
     }
 
 
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java
index a1f08ec..6f7f267 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java
@@ -97,7 +97,12 @@
                 .ingressPoint(cp1)
                 .egressPoint(cp3)
                 .build();
-        compiled = new PathIntent(appId, selector, treatment, path);
+        compiled = PathIntent.builder()
+                .appId(appId)
+                .selector(selector)
+                .treatment(treatment)
+                .path(path)
+                .build();
     }