Committed by
Gerrit Code Review
Add equals, toString, hashCode methods for DefaultSystemInfo
Change-Id: I2d5acc7fb03c2edc28ee6996e774366c9c25910e
Showing
1 changed file
with
39 additions
and
4 deletions
... | @@ -17,14 +17,18 @@ package org.onosproject.cpman.impl; | ... | @@ -17,14 +17,18 @@ package org.onosproject.cpman.impl; |
17 | 17 | ||
18 | import org.onosproject.cpman.SystemInfo; | 18 | import org.onosproject.cpman.SystemInfo; |
19 | 19 | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
23 | + | ||
20 | /** | 24 | /** |
21 | * Implementation class of storing system specification. | 25 | * Implementation class of storing system specification. |
22 | */ | 26 | */ |
23 | public final class DefaultSystemInfo implements SystemInfo { | 27 | public final class DefaultSystemInfo implements SystemInfo { |
24 | - private int numOfCores; | 28 | + private final int numOfCores; |
25 | - private int numOfCpus; | 29 | + private final int numOfCpus; |
26 | - private int cpuSpeedMhz; | 30 | + private final int cpuSpeedMhz; |
27 | - private int totalMemoryMbytes; | 31 | + private final int totalMemoryMbytes; |
28 | 32 | ||
29 | private DefaultSystemInfo(int numOfCores, int numOfCpus, | 33 | private DefaultSystemInfo(int numOfCores, int numOfCpus, |
30 | int cpuSpeedMhz, int totalMemoryMbytes) { | 34 | int cpuSpeedMhz, int totalMemoryMbytes) { |
... | @@ -54,6 +58,37 @@ public final class DefaultSystemInfo implements SystemInfo { | ... | @@ -54,6 +58,37 @@ public final class DefaultSystemInfo implements SystemInfo { |
54 | return this.totalMemoryMbytes; | 58 | return this.totalMemoryMbytes; |
55 | } | 59 | } |
56 | 60 | ||
61 | + | ||
62 | + @Override | ||
63 | + public int hashCode() { | ||
64 | + return Objects.hash(numOfCores, numOfCpus, cpuSpeedMhz, totalMemoryMbytes); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public boolean equals(Object obj) { | ||
69 | + if (this == obj) { | ||
70 | + return true; | ||
71 | + } | ||
72 | + if (obj instanceof DefaultSystemInfo) { | ||
73 | + final DefaultSystemInfo other = (DefaultSystemInfo) obj; | ||
74 | + return Objects.equals(this.numOfCores, other.numOfCores) && | ||
75 | + Objects.equals(this.numOfCpus, other.numOfCpus) && | ||
76 | + Objects.equals(this.cpuSpeedMhz, other.cpuSpeedMhz) && | ||
77 | + Objects.equals(this.totalMemoryMbytes, other.totalMemoryMbytes); | ||
78 | + } | ||
79 | + return false; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public String toString() { | ||
84 | + return toStringHelper(this) | ||
85 | + .add("numOfCores", numOfCores) | ||
86 | + .add("numOfCpus", numOfCpus) | ||
87 | + .add("cpuSpeedMhz", cpuSpeedMhz) | ||
88 | + .add("totalMemoryMbytes", totalMemoryMbytes) | ||
89 | + .toString(); | ||
90 | + } | ||
91 | + | ||
57 | /** | 92 | /** |
58 | * ControlMetricsSystemSpec builder class. | 93 | * ControlMetricsSystemSpec builder class. |
59 | */ | 94 | */ | ... | ... |
-
Please register or login to post a comment