Change some of the basic classes in the "unit/" directory to immutable:
* Change each class to "final"
* Change the fields to "final"
* Remove the "set" methods
Change-Id: I3499489024403b55328ffb1827fc8c3b5ffd231e
diff --git a/src/main/java/net/onrc/onos/core/util/IPv4Net.java b/src/main/java/net/onrc/onos/core/util/IPv4Net.java
index 3aa5a8b..6a04635 100644
--- a/src/main/java/net/onrc/onos/core/util/IPv4Net.java
+++ b/src/main/java/net/onrc/onos/core/util/IPv4Net.java
@@ -8,17 +8,19 @@
/**
* The class representing an IPv4 network address.
+ * This class is immutable.
*/
@JsonDeserialize(using = IPv4NetDeserializer.class)
@JsonSerialize(using = IPv4NetSerializer.class)
-public class IPv4Net {
- private IPv4 address; // The IPv4 address
- private short prefixLen; // The prefix length
+public final class IPv4Net {
+ private final IPv4 address; // The IPv4 address
+ private final short prefixLen; // The prefix length
/**
* Default constructor.
*/
public IPv4Net() {
+ this.address = null;
this.prefixLen = 0;
}
@@ -30,6 +32,8 @@
public IPv4Net(IPv4Net other) {
if (other.address != null)
this.address = new IPv4(other.address);
+ else
+ this.address = null;
this.prefixLen = other.prefixLen;
}
@@ -69,15 +73,6 @@
}
/**
- * Set the address value of the IPv4Net address.
- *
- * @param address the address to use.
- */
- public void setAddress(IPv4 address) {
- this.address = address;
- }
-
- /**
* Get the prefix length value of the IPv4Net address.
*
* @return the prefix length value of the IPv4Net address.
@@ -87,26 +82,6 @@
}
/**
- * Set the prefix length value of the IPv4Net address.
- *
- * @param prefixLen the prefix length to use.
- */
- public void setPrefixLen(short prefixLen) {
- this.prefixLen = prefixLen;
- }
-
- /**
- * Set the value of the IPv4Net address.
- *
- * @param address the address to use.
- * @param prefixLen the prefix length to use.
- */
- public void setValue(IPv4 address, short prefixLen) {
- this.address = address;
- this.prefixLen = prefixLen;
- }
-
- /**
* Convert the IPv4Net value to an "address/prefixLen" string.
*
* @return the IPv4Net value as an "address/prefixLen" string.