Add equals, toString, hashCode methods for DefaultSystemInfo
Change-Id: I2d5acc7fb03c2edc28ee6996e774366c9c25910e
diff --git a/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/DefaultSystemInfo.java b/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/DefaultSystemInfo.java
index e4a301b..22d3bb0 100644
--- a/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/DefaultSystemInfo.java
+++ b/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/DefaultSystemInfo.java
@@ -17,14 +17,18 @@
import org.onosproject.cpman.SystemInfo;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
/**
* Implementation class of storing system specification.
*/
public final class DefaultSystemInfo implements SystemInfo {
- private int numOfCores;
- private int numOfCpus;
- private int cpuSpeedMhz;
- private int totalMemoryMbytes;
+ private final int numOfCores;
+ private final int numOfCpus;
+ private final int cpuSpeedMhz;
+ private final int totalMemoryMbytes;
private DefaultSystemInfo(int numOfCores, int numOfCpus,
int cpuSpeedMhz, int totalMemoryMbytes) {
@@ -54,6 +58,37 @@
return this.totalMemoryMbytes;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(numOfCores, numOfCpus, cpuSpeedMhz, totalMemoryMbytes);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultSystemInfo) {
+ final DefaultSystemInfo other = (DefaultSystemInfo) obj;
+ return Objects.equals(this.numOfCores, other.numOfCores) &&
+ Objects.equals(this.numOfCpus, other.numOfCpus) &&
+ Objects.equals(this.cpuSpeedMhz, other.cpuSpeedMhz) &&
+ Objects.equals(this.totalMemoryMbytes, other.totalMemoryMbytes);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("numOfCores", numOfCores)
+ .add("numOfCpus", numOfCpus)
+ .add("cpuSpeedMhz", cpuSpeedMhz)
+ .add("totalMemoryMbytes", totalMemoryMbytes)
+ .toString();
+ }
+
/**
* ControlMetricsSystemSpec builder class.
*/