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