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/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index badad7f..f08e513 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -15,7 +15,19 @@
  */
 package org.onosproject.sdnip;
 
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Semaphore;
+
 import org.onlab.packet.Ethernet;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
@@ -43,19 +55,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Semaphore;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -340,11 +340,15 @@
         int priority =
             prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
         Key key = Key.of(prefix.toString(), appId);
-        return new MultiPointToSinglePointIntent(appId, key, selector.build(),
-                                                 treatment.build(),
-                                                 ingressPorts, egressPort,
-                                                 Collections.emptyList(),
-                                                 priority);
+        return MultiPointToSinglePointIntent.builder()
+                .appId(appId)
+                .key(key)
+                .selector(selector.build())
+                .treatment(treatment.build())
+                .ingressPoints(ingressPorts)
+                .egressPoint(egressPort)
+                .priority(priority)
+                .build();
     }
 
     @Override
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
index 9f29c1b..7625af6 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
@@ -233,9 +233,13 @@
         ingressPoints.add(SW4_ETH1);
 
         MultiPointToSinglePointIntent intent =
-                new MultiPointToSinglePointIntent(APPID,
-                                                  selectorBuilder.build(), treatmentBuilder.build(),
-                                                  ingressPoints, SW1_ETH1);
+                MultiPointToSinglePointIntent.builder()
+                        .appId(APPID)
+                        .selector(selectorBuilder.build())
+                        .treatment(treatmentBuilder.build())
+                        .ingressPoints(ingressPoints)
+                        .egressPoint(SW1_ETH1)
+                        .build();
 
         // Setup the expected intents
         intentService.submit(eqExceptId(intent));
@@ -291,9 +295,13 @@
         ingressPoints.add(SW3_ETH1);
 
         MultiPointToSinglePointIntent intent =
-                new MultiPointToSinglePointIntent(APPID,
-                        selectorBuilder.build(), treatmentBuilder.build(),
-                        ingressPoints, SW4_ETH1);
+                MultiPointToSinglePointIntent.builder()
+                        .appId(APPID)
+                        .selector(selectorBuilder.build())
+                        .treatment(treatmentBuilder.build())
+                        .ingressPoints(ingressPoints)
+                        .egressPoint(SW4_ETH1)
+                        .build();
 
         // Setup the expected intents
         intentService.submit(eqExceptId(intent));
@@ -357,10 +365,13 @@
         ingressPointsNew.add(SW4_ETH1);
 
         MultiPointToSinglePointIntent intentNew =
-                new MultiPointToSinglePointIntent(APPID,
-                                                  selectorBuilderNew.build(),
-                                                  treatmentBuilderNew.build(),
-                                                  ingressPointsNew, SW2_ETH1);
+                MultiPointToSinglePointIntent.builder()
+                        .appId(APPID)
+                        .selector(selectorBuilderNew.build())
+                        .treatment(treatmentBuilderNew.build())
+                        .ingressPoints(ingressPointsNew)
+                        .egressPoint(SW2_ETH1)
+                        .build();
 
         // Set up test expectation
         reset(intentService);
@@ -592,9 +603,13 @@
             }
         }
         MultiPointToSinglePointIntent intent =
-                new MultiPointToSinglePointIntent(APPID,
-                        selectorBuilder.build(), treatmentBuilder.build(),
-                        ingressPoints, egressPoint);
+                MultiPointToSinglePointIntent.builder()
+                        .appId(APPID)
+                        .selector(selectorBuilder.build())
+                        .treatment(treatmentBuilder.build())
+                        .ingressPoints(ingressPoints)
+                        .egressPoint(egressPoint)
+                        .build();
         return intent;
     }