Fixed some PMD issues in the SDN-IP module
Change-Id: Iaf002e70c1a00f0008edef5e77b91579acf146aa
diff --git a/src/main/java/net/onrc/onos/apps/bgproute/Prefix.java b/src/main/java/net/onrc/onos/apps/bgproute/Prefix.java
index 5e5ba91..74b6ad9 100644
--- a/src/main/java/net/onrc/onos/apps/bgproute/Prefix.java
+++ b/src/main/java/net/onrc/onos/apps/bgproute/Prefix.java
@@ -7,7 +7,7 @@
import com.google.common.net.InetAddresses;
public class Prefix {
- private final int MAX_BYTES = 4;
+ private static final int MAX_BYTES = 4;
private final int prefixLength;
private final byte[] address;
@@ -27,7 +27,7 @@
try {
inetAddress = InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Couldn't parse IP address", e);
}
}
@@ -46,7 +46,7 @@
try {
inetAddress = InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Couldn't parse IP address", e);
}
}
@@ -94,7 +94,7 @@
@Override
public boolean equals(Object other) {
- if (other == null || !(other instanceof Prefix)) {
+ if (!(other instanceof Prefix)) {
return false;
}
@@ -118,17 +118,17 @@
}
public String printAsBits() {
- String result = "";
+ StringBuilder result = new StringBuilder();
for (int i = 0; i < address.length; i++) {
byte b = address[i];
for (int j = 0; j < Byte.SIZE; j++) {
byte mask = (byte) (0x80 >>> j);
- result += ((b & mask) == 0) ? "0" : "1";
+ result.append(((b & mask) == 0) ? "0" : "1");
if (i * Byte.SIZE + j == prefixLength - 1) {
- return result;
+ return result.toString();
}
}
- result += " ";
+ result.append(" ");
}
return result.substring(0, result.length() - 1);
}