Bugfix: OpticalPortOperator should be able to overwrite port number.

- bug introduced in ONOS-3503.
- added exact equality comparison method to PortNumber
- removed null PortNumber case handling test

Change-Id: I6d1f191b5a64b79426de9d80cffadd6c9de96d56
diff --git a/core/api/src/main/java/org/onosproject/net/PortNumber.java b/core/api/src/main/java/org/onosproject/net/PortNumber.java
index 96c4eb0..e1a1554 100644
--- a/core/api/src/main/java/org/onosproject/net/PortNumber.java
+++ b/core/api/src/main/java/org/onosproject/net/PortNumber.java
@@ -15,6 +15,7 @@
  */
 package org.onosproject.net;
 
+import com.google.common.base.Objects;
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableMap;
@@ -273,4 +274,21 @@
         }
         return false;
     }
+
+    /**
+     * Indicates whether some other PortNumber object is equal to this one
+     * including it's name.
+     *
+     * @param that other {@link PortNumber} instance to compare
+     * @return true if equal, false otherwise
+     */
+    public boolean exactlyEquals(PortNumber that) {
+        if (this == that) {
+            return true;
+        }
+
+        return this.equals(that) &&
+               this.hasName == that.hasName &&
+               Objects.equal(this.name, that.name);
+    }
 }
diff --git a/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java b/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java
index a507e49..ca57944 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java
@@ -20,6 +20,7 @@
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.SparseAnnotations;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onosproject.net.Port.Type;
 import com.google.common.base.Objects;
 
@@ -61,7 +62,7 @@
                                   Type type, long portSpeed,
                                   SparseAnnotations...annotations) {
         super(annotations);
-        this.number = number;
+        this.number = checkNotNull(number);
         this.isEnabled = isEnabled;
         this.type = type;
         this.portSpeed = portSpeed;
diff --git a/core/api/src/test/java/org/onosproject/net/PortNumberTest.java b/core/api/src/test/java/org/onosproject/net/PortNumberTest.java
index c31e1c8..adba71f 100644
--- a/core/api/src/test/java/org/onosproject/net/PortNumberTest.java
+++ b/core/api/src/test/java/org/onosproject/net/PortNumberTest.java
@@ -21,7 +21,7 @@
 import org.onosproject.net.PortNumber.Logical;
 
 import static java.util.stream.Collectors.toList;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 import static org.onosproject.net.PortNumber.portNumber;
 
 import java.util.List;
@@ -77,4 +77,16 @@
         ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString())));
     }
 
+    @Test
+    public void exactlyEquals() {
+        assertTrue(portNumber(0).exactlyEquals(portNumber(0)));
+        assertTrue(portNumber(0, "foo").exactlyEquals(portNumber(0, "foo")));
+
+        assertFalse(portNumber(0, "foo").exactlyEquals(portNumber(0, "bar")));
+        assertFalse(portNumber(0, "foo").exactlyEquals(portNumber(0)));
+        assertFalse(portNumber(0, "foo").exactlyEquals(portNumber(1, "foo")));
+
+        assertFalse(portNumber(123).exactlyEquals(portNumber(123, "123")));
+    }
+
 }