private static final long serialVersionUID = 1L;
// Key fields
private InetAddress networkAddress;
+ private transient InetAddress subnetPrefix;
private short subnetMaskLength;
// Property fields
private short vlan;
*/
public Subnet setNetworkAddress(InetAddress networkAddress) {
this.networkAddress = networkAddress;
+ this.subnetPrefix = null;
return this;
}
if (ip == null) {
return false;
}
- InetAddress thisPrefix = getPrefixForAddress(this.networkAddress);
- InetAddress otherPrefix = getPrefixForAddress(ip);
- if ((thisPrefix == null) || (otherPrefix == null)) {
- return false;
- }
- if (thisPrefix.equals(otherPrefix)) {
- return true;
+ if(subnetPrefix == null) {
+ subnetPrefix = getPrefixForAddress(this.networkAddress);
}
- else {
- return false;
+ InetAddress otherPrefix = getPrefixForAddress(ip);
+ boolean isSubnetOf = true;
+ if (((subnetPrefix == null) || (otherPrefix == null)) || (!subnetPrefix.equals(otherPrefix)) ) {
+ isSubnetOf = false;
}
+ return isSubnetOf;
}
public short getVlan() {
}
public boolean isMutualExclusive(Subnet otherSubnet) {
- if (this.networkAddress.getClass() != otherSubnet.networkAddress
- .getClass()) {
- return true;
- }
- if (this.isSubnetOf(otherSubnet.getNetworkAddress())) {
- return false;
- }
- if (otherSubnet.isSubnetOf(this.getNetworkAddress())) {
- return false;
- }
- return true;
+ return !(isSubnetOf(otherSubnet.getNetworkAddress()) || otherSubnet.isSubnetOf(getNetworkAddress()));
}
/**