Before this change, subnet prefix was calculated on every
'isSubnetOf' call. Since the prefix is not changing unless
the subnet address itself changed, it's sufficient to do it only once
and keep it as part of the Subnet object.
Marked it as transient so it will not be serialized - it can be
calculated from the rest of the info of Subnet anytime after
deserialization.
Change-Id: Ie16bf80713820b566864bea0ff46298c93cc2d47
Signed-off-by: Alissa Bonas <abonas@redhat.com>
private static final long serialVersionUID = 1L;
// Key fields
private InetAddress networkAddress;
private static final long serialVersionUID = 1L;
// Key fields
private InetAddress networkAddress;
+ private transient InetAddress subnetPrefix;
private short subnetMaskLength;
// Property fields
private short vlan;
private short subnetMaskLength;
// Property fields
private short vlan;
*/
public Subnet setNetworkAddress(InetAddress networkAddress) {
this.networkAddress = networkAddress;
*/
public Subnet setNetworkAddress(InetAddress networkAddress) {
this.networkAddress = networkAddress;
+ this.subnetPrefix = null;
if (ip == null) {
return false;
}
if (ip == null) {
return false;
}
- InetAddress thisPrefix = getPrefixForAddress(this.networkAddress);
+ if(subnetPrefix == null) {
+ subnetPrefix = getPrefixForAddress(this.networkAddress);
+ }
InetAddress otherPrefix = getPrefixForAddress(ip);
boolean isSubnetOf = true;
InetAddress otherPrefix = getPrefixForAddress(ip);
boolean isSubnetOf = true;
- if (((thisPrefix == null) || (otherPrefix == null)) || (!thisPrefix.equals(otherPrefix)) ) {
+ if (((subnetPrefix == null) || (otherPrefix == null)) || (!subnetPrefix.equals(otherPrefix)) ) {
isSubnetOf = false;
}
return isSubnetOf;
isSubnetOf = false;
}
return isSubnetOf;