Fix for bug 742. 70/6270/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 4 Mar 2014 11:07:04 +0000 (20:07 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Fri, 18 Apr 2014 08:36:16 +0000 (08:36 +0000)
Bug fix for equals(Object) in virtual node path classes.

Virtual node paths of different types should be treated as different
objects even if they have the same path components.

Change-Id: If2e6ab3cfc1436b8a14210e63284190c284957f8
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
(cherry picked from commit 4b20f15c9d54b6cf7a8259b70b3e480ad5d95ee8)

manager/api/src/main/java/org/opendaylight/vtn/manager/VBridgeIfPath.java
manager/api/src/main/java/org/opendaylight/vtn/manager/VBridgePath.java
manager/api/src/main/java/org/opendaylight/vtn/manager/VTenantPath.java
manager/api/src/test/java/org/opendaylight/vtn/manager/VBridgeIfPathTest.java
manager/api/src/test/java/org/opendaylight/vtn/manager/VBridgePathTest.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/VlanMapPath.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/cluster/VlanMapPathTest.java

index 4e0585295baaf2e84d0b8d7d0e78e4c2a444f304..4c75dd145ec49aa01a450f72b9f945bf70c60e5f 100644 (file)
@@ -29,7 +29,7 @@ public class VBridgeIfPath extends VBridgePath {
     /**
      * Version number for serialization.
      */
-    private static final long serialVersionUID = -5494415245844633625L;
+    private static final long serialVersionUID = -4217150774548362963L;
 
     /**
      * The name of the
@@ -111,6 +111,27 @@ public class VBridgeIfPath extends VBridgePath {
         return builder;
     }
 
+    /**
+     * Determine whether all components in the given path equal to components
+     * in this object or not.
+     *
+     * @param path  An object to be compared.
+     * @return   {@code true} if all path components in {@code path} are
+     *           identical to components in this object.
+     *           Otherwise {@code false}.
+     */
+    protected final boolean equalsPath(VBridgeIfPath path) {
+        if (!equalsPath((VBridgePath)path)) {
+            return false;
+        }
+
+        if (ifName == null) {
+            return (path.ifName == null);
+        }
+
+        return ifName.equals(path.ifName);
+    }
+
     /**
      * Determine whether the given object is identical to this object.
      *
@@ -120,6 +141,8 @@ public class VBridgeIfPath extends VBridgePath {
      * <ul>
      *   <li>
      *     {@code o} is a {@code VBridgeIfPath} object.
+     *     Note that this method returns {@code false} if {@code o} is an
+     *     object of subclass of {@code VBridgeIfPath}.
      *   </li>
      *   <li>
      *     The following values stored in {@code o} are the same as in this
@@ -149,16 +172,11 @@ public class VBridgeIfPath extends VBridgePath {
         if (o == this) {
             return true;
         }
-        if (!(o instanceof VBridgeIfPath) || !super.equals(o)) {
+        if (o == null || !o.getClass().equals(VBridgeIfPath.class)) {
             return false;
         }
 
-        VBridgeIfPath path = (VBridgeIfPath)o;
-        if (ifName == null) {
-            return (path.ifName == null);
-        }
-
-        return ifName.equals(path.ifName);
+        return equalsPath((VBridgeIfPath)o);
     }
 
     /**
index 371284d370b88f923b7008cd9e17e7d8bf3e422e..682fa0d406c55f8acf2a21a2cfb452b30e5abdcf 100644 (file)
@@ -27,7 +27,7 @@ public class VBridgePath extends VTenantPath {
     /**
      * Version number for serialization.
      */
-    private static final long serialVersionUID = 49188209943135523L;
+    private static final long serialVersionUID = -8958896997703009257L;
 
     /**
      * The name of the
@@ -108,6 +108,27 @@ public class VBridgePath extends VTenantPath {
         return builder;
     }
 
+    /**
+     * Determine whether all components in the given path equal to components
+     * in this object or not.
+     *
+     * @param path  An object to be compared.
+     * @return   {@code true} if all path components in {@code path} are
+     *           identical to components in this object.
+     *           Otherwise {@code false}.
+     */
+    protected final boolean equalsPath(VBridgePath path) {
+        if (!equalsPath((VTenantPath)path)) {
+            return false;
+        }
+
+        if (bridgeName == null) {
+            return (path.bridgeName == null);
+        }
+
+        return bridgeName.equals(path.bridgeName);
+    }
+
     /**
      * Determine whether the given object is identical to this object.
      *
@@ -117,6 +138,8 @@ public class VBridgePath extends VTenantPath {
      * <ul>
      *   <li>
      *     {@code o} is a {@code VBridgePath} object.
+     *     Note that this method returns {@code false} if {@code o} is an
+     *     object of subclass of {@code VBridgePath}.
      *   </li>
      *   <li>
      *     The following values stored in {@code o} are the same as in this
@@ -142,16 +165,11 @@ public class VBridgePath extends VTenantPath {
         if (o == this) {
             return true;
         }
-        if (!(o instanceof VBridgePath) || !super.equals(o)) {
+        if (o == null || !o.getClass().equals(VBridgePath.class)) {
             return false;
         }
 
-        VBridgePath path = (VBridgePath)o;
-        if (bridgeName == null) {
-            return (path.bridgeName == null);
-        }
-
-        return bridgeName.equals(path.bridgeName);
+        return equalsPath((VBridgePath)o);
     }
 
     /**
index 1e0ea07b3854919bb0ea0463ace4f4c896a3b72c..9baf49b0bd09fbd5e751ea033f7744fef97d55ed 100644 (file)
@@ -27,7 +27,7 @@ public class VTenantPath implements Serializable {
     /**
      * Version number for serialization.
      */
-    private static final long serialVersionUID = 5295435248672675596L;
+    private static final long serialVersionUID = 6666863891351658965L;
 
     /**
      * The name of the {@linkplain <a href="package-summary.html#VTN">VTN</a>}.
@@ -79,6 +79,23 @@ public class VTenantPath implements Serializable {
         return new StringBuilder(name);
     }
 
+    /**
+     * Determine whether all components in the given path equal to components
+     * in this object or not.
+     *
+     * @param path  An object to be compared.
+     * @return   {@code true} if all path components in {@code path} are
+     *           identical to components in this object.
+     *           Otherwise {@code false}.
+     */
+    protected final boolean equalsPath(VTenantPath path) {
+        if (tenantName == null) {
+            return (path.tenantName == null);
+        }
+
+        return tenantName.equals(path.tenantName);
+    }
+
     /**
      * Determine whether the given object is identical to this object.
      *
@@ -88,6 +105,8 @@ public class VTenantPath implements Serializable {
      * <ul>
      *   <li>
      *     {@code o} is a {@code VTenantPath} object.
+     *     Note that this method returns {@code false} if {@code o} is an
+     *     object of subclass of {@code VTenantPath}.
      *   </li>
      *   <li>
      *     The name of the
@@ -104,16 +123,11 @@ public class VTenantPath implements Serializable {
         if (o == this) {
             return true;
         }
-        if (!(o instanceof VTenantPath)) {
+        if (o == null || !o.getClass().equals(VTenantPath.class)) {
             return false;
         }
 
-        VTenantPath path = (VTenantPath)o;
-        if (tenantName == null) {
-            return (path.tenantName == null);
-        }
-
-        return tenantName.equals(path.tenantName);
+        return equalsPath((VTenantPath)o);
     }
 
     /**
index 180f6ff74469860e247b67586fd57b6839ec5e00..df4cc9cbab4ba3b23cdef5aa077a24c2476900fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -53,13 +53,23 @@ public class VBridgeIfPathTest extends TestBase {
         List<String> bnames = createStrings("bridge");
         List<String> inames = createStrings("ifname");
         for (String tname: tnames) {
+            VTenantPath tpath = new VTenantPath(tname);
             for (String bname: bnames) {
+                VBridgePath bpath = new VBridgePath(tname, bname);
                 for (String iname: inames) {
                     VBridgeIfPath p1 = new VBridgeIfPath(tname, bname, iname);
                     VBridgeIfPath p2 =
                         new VBridgeIfPath(copy(tname), copy(bname),
                                           copy(iname));
                     testEquals(set, p1, p2);
+
+                    // A instance of VTenantPath and VBridgePath must be
+                    // treated as different object even if it has the same
+                    // path component.
+                    assertFalse(tpath.equals(p1));
+                    assertFalse(p1.equals(tpath));
+                    assertFalse(bpath.equals(p1));
+                    assertFalse(p1.equals(bpath));
                 }
             }
         }
index be77dd64e930b163840c9553d623b28f6920c7a4..7112902adbf0ac9044828f3e37f2bf9452db09ed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -47,10 +47,16 @@ public class VBridgePathTest extends TestBase {
         List<String> tnames = createStrings("tenant");
         List<String> bnames = createStrings("bridge");
         for (String tname: tnames) {
+            VTenantPath tpath = new VTenantPath(tname);
             for (String bname: bnames) {
                 VBridgePath p1 = new VBridgePath(tname, bname);
                 VBridgePath p2 = new VBridgePath(copy(tname), copy(bname));
                 testEquals(set, p1, p2);
+
+                // VTenantPath object that has the same tenant name must be
+                // treated as different object.
+                assertFalse(p1.equals(tpath));
+                assertFalse(tpath.equals(p1));
             }
         }
 
index 55a9842410e0f4e09231d2eda80bc5a108f017d5..69245289d183560d9f0d191927ac1625f1edb177 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -25,7 +25,7 @@ public class VlanMapPath extends VBridgePath {
     /**
      * Version number for serialization.
      */
-    private static final long serialVersionUID = 556981779172308505L;
+    private static final long serialVersionUID = -5858869883027125836L;
 
     /**
      * Identifier of the VLAN mapping.
@@ -68,6 +68,23 @@ public class VlanMapPath extends VBridgePath {
         return builder;
     }
 
+    /**
+     * Determine whether all components in the given path equal to components
+     * in this object or not.
+     *
+     * @param path  An object to be compared.
+     * @return   {@code true} if all path components in {@code path} are
+     *           identical to components in this object.
+     *           Otherwise {@code false}.
+     */
+    protected final boolean equalsPath(VlanMapPath path) {
+        if (!equalsPath((VBridgePath)path)) {
+            return false;
+        }
+
+        return mapId.equals(path.mapId);
+    }
+
     /**
      * Determine whether the given object is identical to this object.
      *
@@ -79,12 +96,11 @@ public class VlanMapPath extends VBridgePath {
         if (o == this) {
             return true;
         }
-        if (!(o instanceof VlanMapPath) || !super.equals(o)) {
+        if (o == null || !o.getClass().equals(VlanMapPath.class)) {
             return false;
         }
 
-        VlanMapPath path = (VlanMapPath)o;
-        return mapId.equals(path.mapId);
+        return equalsPath((VlanMapPath)o);
     }
 
     /**
index 94f897505bb3d6d710f5aaa8d39dd0df45dd4cf7..bffb7386efb84ea588b5449883d90b8ba7b9c88e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -14,6 +14,7 @@ import java.util.List;
 
 import org.junit.Test;
 
+import org.opendaylight.vtn.manager.VTenantPath;
 import org.opendaylight.vtn.manager.VBridgePath;
 import org.opendaylight.vtn.manager.VBridgeIfPath;
 import org.opendaylight.vtn.manager.internal.TestBase;
@@ -52,6 +53,7 @@ public class VlanMapPathTest extends TestBase {
         List<String> bnames = createStrings("bridge");
         List<String> mapIds = createStrings("mapId", false);
         for (String tname: tnames) {
+            VTenantPath tpath = new VTenantPath(tname);
             for (String bname: bnames) {
                 VBridgePath bp1 = new VBridgePath(tname, bname);
                 VBridgePath bp2 = new VBridgePath(copy(tname), copy(bname));
@@ -69,6 +71,15 @@ public class VlanMapPathTest extends TestBase {
                             ifPath.equals(p1));
                     assertFalse("(p2)" + p2.toString() + ",(ifPath)" + ifPath.toString(),
                             ifPath.equals(p2));
+
+                    // A instance of VTenantPath, VBridgePath must be treated
+                    // as different object even if it has the same path
+                    // component.
+                    assertFalse(p1.equals(tpath));
+                    assertFalse(tpath.equals(p1));
+
+                    assertFalse(p1.equals(bp1));
+                    assertFalse(bp1.equals(p1));
                 }
             }
         }