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/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index 60306b2..feea42f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -97,9 +97,14 @@
                                     HostToHostIntent intent) {
         TrafficSelector selector = builder(intent.selector())
                 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
-        return new PathIntent(intent.appId(), selector, intent.treatment(),
-                              path, intent.constraints(),
-                              intent.priority());
+        return PathIntent.builder()
+                .appId(intent.appId())
+                .selector(selector)
+                .treatment(intent.treatment())
+                .path(path)
+                .constraints(intent.constraints())
+                .priority(intent.priority())
+                .build();
     }
 
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
index 948dbd6..b59d7eb 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
@@ -75,11 +75,16 @@
      */
     private Intent createPathIntent(Path path,
                                     MplsIntent intent) {
-        return new MplsPathIntent(intent.appId(),
-                              intent.selector(), intent.treatment(), path,
-                              intent.ingressLabel(), intent.egressLabel(),
-                              intent.constraints(),
-                              intent.priority());
+        return MplsPathIntent.builder()
+                .appId(intent.appId())
+                .selector(intent.selector())
+                .treatment(intent.treatment())
+                .path(path)
+                .ingressLabel(intent.ingressLabel())
+                .egressLabel(intent.egressLabel())
+                .constraints(intent.constraints())
+                .priority(intent.priority())
+                .build();
     }
 
 
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index 6403019..fbdfa9c 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -16,7 +16,6 @@
 package org.onosproject.net.intent.impl.compiler;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -89,14 +88,16 @@
             }
         }
 
-        Set<ConnectPoint> egress = ImmutableSet.of(intent.egressPoint());
-        Intent result = new LinkCollectionIntent(intent.appId(),
-                                                 intent.selector(), intent.treatment(),
-                                                 Sets.newHashSet(links.values()),
-                                                 intent.ingressPoints(),
-                                                 ImmutableSet.of(intent.egressPoint()),
-                                                 Collections.emptyList(),
-                                                 intent.priority());
+        Intent result = LinkCollectionIntent.builder()
+                .appId(intent.appId())
+                .selector(intent.selector())
+                .treatment(intent.treatment())
+                .links(Sets.newHashSet(links.values()))
+                .ingressPoints(intent.ingressPoints())
+                .egressPoints(ImmutableSet.of(intent.egressPoint()))
+                .priority(intent.priority())
+                .build();
+
         return Arrays.asList(result);
     }
 
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index 0f897a4..208c8e2 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -91,10 +91,14 @@
      */
     private Intent createPathIntent(Path path,
                                     PointToPointIntent intent) {
-        return new PathIntent(intent.appId(),
-                              intent.selector(), intent.treatment(), path,
-                              intent.constraints(),
-                              intent.priority());
+        return PathIntent.builder()
+                .appId(intent.appId())
+                .selector(intent.selector())
+                .treatment(intent.treatment())
+                .path(path)
+                .constraints(intent.constraints())
+                .priority(intent.priority())
+                .build();
     }
 
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
index 4b2260e..8a97b7b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
@@ -16,7 +16,6 @@
 package org.onosproject.net.intent.impl.compiler;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -66,13 +65,16 @@
             links.addAll(path.links());
         }
 
-        Intent result = new LinkCollectionIntent(intent.appId(),
-                                                 intent.selector(),
-                                                 intent.treatment(), links,
-                                                 ImmutableSet.of(intent.ingressPoint()),
-                                                 intent.egressPoints(),
-                                                 Collections.emptyList(),
-                                                 intent.priority());
+        Intent result = LinkCollectionIntent.builder()
+                .appId(intent.appId())
+                .key(intent.key())
+                .selector(intent.selector())
+                .treatment(intent.treatment())
+                .links(links)
+                .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
+                .egressPoints(intent.egressPoints())
+                .priority(intent.priority())
+                .build();
 
         return Arrays.asList(result);
     }
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();
     }