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/main/java/org/onosproject/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
index 9b00512..157397a 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
@@ -15,20 +15,16 @@
  */
 package org.onosproject.net.intent;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableList;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.HostId;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.constraint.LinkTypeConstraint;
-
 import java.util.Collections;
 import java.util.List;
 
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+
+import com.google.common.base.MoreObjects;
+
 import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
@@ -40,59 +36,98 @@
     private final HostId two;
 
     /**
-     * Creates a new host-to-host intent with the supplied host pair and no
-     * other traffic selection or treatment criteria.
+     * Returns a new host to host intent builder.
      *
-     * @param appId     application identifier
-     * @param one       first host
-     * @param two       second host
-     * @throws NullPointerException if {@code one} or {@code two} is null.
+     * @return host to host intent builder
      */
-    public HostToHostIntent(ApplicationId appId, HostId one, HostId two) {
-        this(appId, one, two,
-             DefaultTrafficSelector.emptySelector(),
-             DefaultTrafficTreatment.emptyTreatment(),
-             ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)),
-             DEFAULT_INTENT_PRIORITY);
+    public static Builder builder() {
+        return new Builder();
     }
 
     /**
-     * Creates a new host-to-host intent with the supplied host pair.
-     *
-     * @param appId     application identifier
-     * @param one       first host
-     * @param two       second host
-     * @param selector  action
-     * @param treatment ingress port
-     * @throws NullPointerException if {@code one} or {@code two} is null.
+     * Builder of a host to host intent.
      */
-    public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
-                            TrafficSelector selector,
-                            TrafficTreatment treatment) {
-        this(appId, one, two, selector, treatment,
-             ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)),
-             DEFAULT_INTENT_PRIORITY);
+    public static final class Builder extends ConnectivityIntent.Builder {
+        HostId one;
+        HostId two;
+
+        private Builder() {
+            // Hide constructor
+        }
+
+        @Override
+        public Builder appId(ApplicationId appId) {
+            return (Builder) super.appId(appId);
+        }
+
+        @Override
+        public Builder key(Key key) {
+            return (Builder) super.key(key);
+        }
+
+        @Override
+        public Builder selector(TrafficSelector selector) {
+            return (Builder) super.selector(selector);
+        }
+
+        @Override
+        public Builder treatment(TrafficTreatment treatment) {
+            return (Builder) super.treatment(treatment);
+        }
+
+        @Override
+        public Builder constraints(List<Constraint> constraints) {
+            return (Builder) super.constraints(constraints);
+        }
+
+        @Override
+        public Builder priority(int priority) {
+            return (Builder) super.priority(priority);
+        }
+
+        /**
+         * Sets the first host of the intent that will be built.
+         *
+         * @param one first host
+         * @return this builder
+         */
+        public Builder one(HostId one) {
+            this.one = one;
+            return this;
+        }
+
+        /**
+         * Sets the second host of the intent that will be built.
+         *
+         * @param two second host
+         * @return this builder
+         */
+        public Builder two(HostId two) {
+            this.two = two;
+            return this;
+        }
+
+        /**
+         * Builds a host to host intent from the accumulated parameters.
+         *
+         * @return point to point intent
+         */
+        public HostToHostIntent build() {
+
+            return new HostToHostIntent(
+                    appId,
+                    key,
+                    one,
+                    two,
+                    selector,
+                    treatment,
+                    constraints,
+                    priority
+            );
+        }
     }
 
-    /**
-     * Creates a new host-to-host intent with the supplied host pair.
-     *
-     * @param appId       application identifier
-     * @param one         first host
-     * @param two         second host
-     * @param selector    action
-     * @param treatment   ingress port
-     * @param constraints optional prioritized list of path selection constraints
-     * @param priority    priority to use for flows generated by this intent
-     * @throws NullPointerException if {@code one} or {@code two} is null.
-     */
-    public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
-                            TrafficSelector selector,
-                            TrafficTreatment treatment,
-                            List<Constraint> constraints,
-                            int priority) {
-        this(appId, null, one, two, selector, treatment, constraints, priority);
-    }
+
     /**
      * Creates a new host-to-host intent with the supplied host pair.
      *
@@ -106,7 +141,7 @@
      * @param priority    priority to use for flows generated by this intent
      * @throws NullPointerException if {@code one} or {@code two} is null.
      */
-    public HostToHostIntent(ApplicationId appId, Key key,
+    private HostToHostIntent(ApplicationId appId, Key key,
                             HostId one, HostId two,
                             TrafficSelector selector,
                             TrafficTreatment treatment,
@@ -121,14 +156,6 @@
 
     }
 
-    private static HostId min(HostId one, HostId two) {
-        return one.hashCode() < two.hashCode() ? one : two;
-    }
-
-    private static HostId max(HostId one, HostId two) {
-        return one.hashCode() >= two.hashCode() ? one : two;
-    }
-
     /**
      * Returns identifier of the first host.
      *