mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 09:46:13 +00:00
fix equals() methods
This commit is contained in:
parent
f12c75e68b
commit
f8ba1962e6
@ -32,6 +32,7 @@ import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
|
||||
public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096;
|
||||
@ -57,39 +58,42 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
|
||||
}
|
||||
|
||||
public boolean equals(VirtualNetworkConfig cfg) {
|
||||
boolean aaEqual = true;
|
||||
if(assignedAddresses.length == cfg.assignedAddresses.length) {
|
||||
for(int i = 0; i < assignedAddresses.length; ++i) {
|
||||
if(!assignedAddresses[i].equals(cfg.assignedAddresses[i])) {
|
||||
aaEqual = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
aaEqual = false;
|
||||
ArrayList<String> current = new ArrayList<>();
|
||||
ArrayList<String> newConfig = new ArrayList<>();
|
||||
for (InetSocketAddress s : assignedAddresses) {
|
||||
current.add(s.toString());
|
||||
}
|
||||
|
||||
boolean routesEqual = true;
|
||||
if(routes.length == cfg.routes.length) {
|
||||
for (int i = 0; i < routes.length; ++i) {
|
||||
if (!routes[i].equals(cfg.routes[i])) {
|
||||
routesEqual = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
routesEqual = false;
|
||||
for (InetSocketAddress s : cfg.assignedAddresses) {
|
||||
newConfig.add(s.toString());
|
||||
}
|
||||
Collections.sort(current);
|
||||
Collections.sort(newConfig);
|
||||
boolean aaEqual = current.equals(newConfig);
|
||||
|
||||
return nwid == cfg.nwid &&
|
||||
mac == cfg.mac &&
|
||||
name.equals(cfg.name) &&
|
||||
status.equals(cfg.status) &&
|
||||
type.equals(cfg.type) &&
|
||||
mtu == cfg.mtu &&
|
||||
dhcp == cfg.dhcp &&
|
||||
bridge == cfg.bridge &&
|
||||
broadcastEnabled == cfg.broadcastEnabled &&
|
||||
portError == cfg.portError &&
|
||||
enabled == cfg.enabled &&
|
||||
current.clear();
|
||||
newConfig.clear();
|
||||
|
||||
for (VirtualNetworkRoute r : routes) {
|
||||
current.add(r.toString());
|
||||
}
|
||||
for (VirtualNetworkRoute r : cfg.routes) {
|
||||
newConfig.add(r.toString());
|
||||
}
|
||||
Collections.sort(current);
|
||||
Collections.sort(newConfig);
|
||||
boolean routesEqual = current.equals(newConfig);
|
||||
|
||||
return this.nwid == cfg.nwid &&
|
||||
this.mac == cfg.mac &&
|
||||
this.name.equals(cfg.name) &&
|
||||
this.status.equals(cfg.status) &&
|
||||
this.type.equals(cfg.type) &&
|
||||
this.mtu == cfg.mtu &&
|
||||
this.dhcp == cfg.dhcp &&
|
||||
this.bridge == cfg.bridge &&
|
||||
this.broadcastEnabled == cfg.broadcastEnabled &&
|
||||
this.portError == cfg.portError &&
|
||||
this.enabled == cfg.enabled &&
|
||||
aaEqual && routesEqual;
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,23 @@ public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute
|
||||
*/
|
||||
public int metric;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(target.toString());
|
||||
if (via != null) {
|
||||
sb.append(via.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VirtualNetworkRoute other) {
|
||||
return target.toString().compareTo(other.target.toString());
|
||||
return this.toString().compareTo(other.toString());
|
||||
}
|
||||
|
||||
public boolean equals(VirtualNetworkRoute other) {
|
||||
boolean targetEquals;
|
||||
boolean targetEquals = false;
|
||||
if (target == null && other.target == null) {
|
||||
targetEquals = true;
|
||||
}
|
||||
@ -76,7 +85,7 @@ public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute
|
||||
targetEquals = false;
|
||||
}
|
||||
else {
|
||||
targetEquals = target.equals(other.target);
|
||||
targetEquals = target.toString().equals(other.target.toString());
|
||||
}
|
||||
|
||||
|
||||
@ -91,12 +100,10 @@ public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute
|
||||
viaEquals = false;
|
||||
}
|
||||
else {
|
||||
viaEquals = via.equals(other.via);
|
||||
viaEquals = via.toString().equals(other.via.toString());
|
||||
}
|
||||
|
||||
return viaEquals &&
|
||||
viaEquals &&
|
||||
flags == other.flags &&
|
||||
metric == other.metric;
|
||||
viaEquals;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user