Jelajahi Sumber

reimplement VirtualNetworkRoute.equals

Brenton Bostick 2 tahun lalu
induk
melakukan
86122e1646
1 mengubah file dengan 48 tambahan dan 21 penghapusan
  1. 48 21
      java/src/com/zerotier/sdk/VirtualNetworkRoute.java

+ 48 - 21
java/src/com/zerotier/sdk/VirtualNetworkRoute.java

@@ -73,36 +73,63 @@ public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute
         return this.toString().compareTo(other.toString());
 	}
 
-    public boolean equals(VirtualNetworkRoute other) {
-        boolean targetEquals = false;
-        if (target == null && other.target == null) {
-            targetEquals = true;
-        }
-        else if (target == null && other.target != null) {
-            targetEquals = false;
-        }
-        else if (target != null && other.target == null) {
-            targetEquals = false;
+    @Override
+    public boolean equals(Object o) {
+
+        if (!(o instanceof VirtualNetworkRoute)) {
+            return false;
         }
-        else {
-            targetEquals = target.toString().equals(other.target.toString());
+
+        VirtualNetworkRoute other = (VirtualNetworkRoute) o;
+
+        boolean targetEquals;
+        if (target == null) {
+            //noinspection RedundantIfStatement
+            if (other.target == null) {
+                targetEquals = true;
+            } else {
+                targetEquals = false;
+            }
+        } else {
+            if (other.target == null) {
+                targetEquals = false;
+            } else {
+                targetEquals = target.equals(other.target);
+            }
         }
 
+        if (!targetEquals) {
+            return false;
+        }
 
         boolean viaEquals;
-        if (via == null && other.via == null) {
-            viaEquals = true;
+        if (via == null) {
+            //noinspection RedundantIfStatement
+            if (other.via == null) {
+                viaEquals = true;
+            } else {
+                viaEquals = false;
+            }
+        } else {
+            if (other.via == null) {
+                viaEquals = false;
+            } else {
+                viaEquals = via.equals(other.via);
+            }
         }
-        else if (via == null && other.via != null) {
-            viaEquals = false;
+
+        if (!viaEquals) {
+            return false;
         }
-        else if (via != null && other.via == null) {
-            viaEquals = false;
+
+        if (flags != other.flags) {
+            return false;
         }
-        else {
-            viaEquals = via.toString().equals(other.via.toString());
+
+        if (metric != other.metric) {
+            return false;
         }
 
-        return viaEquals && targetEquals;
+        return true;
     }
 }