blob: 5b48e63cdb8413955dd4df97e3a7ed168f2fa387 [file] [log] [blame]
alshabib7911a052014-10-16 17:49:37 -07001package org.onlab.packet;
2
3/**
4 * The class representing a network device chassisId.
5 * This class is immutable.
6 */
7// TODO: Move this to a reasonable place.
8public final class ChassisId {
9
10 private static final long UNKNOWN = 0;
11 private final long value;
12
13 /**
14 * Default constructor.
15 */
16 public ChassisId() {
17 this.value = ChassisId.UNKNOWN;
18 }
19
20 /**
21 * Constructor from a long value.
22 *
23 * @param value the value to use.
24 */
25 public ChassisId(long value) {
26 this.value = value;
27 }
28
29 /**
30 * Constructor from a string.
31 *
32 * @param value the value to use.
33 */
34 public ChassisId(String value) {
Thomas Vachuska9252bc32014-10-23 02:33:25 -070035 this.value = Long.valueOf(value, 16);
alshabib7911a052014-10-16 17:49:37 -070036 }
37
38 /**
39 * Get the value of the chassis id.
40 *
41 * @return the value of the chassis id.
42 */
43 public long value() {
44 return value;
45 }
46
47 /**
48 * Convert the Chassis Id value to a ':' separated hexadecimal string.
49 *
50 * @return the Chassis Id value as a ':' separated hexadecimal string.
51 */
52 @Override
53 public String toString() {
54 return Long.toHexString(this.value);
55 }
56
57 @Override
58 public boolean equals(Object other) {
59 if (!(other instanceof ChassisId)) {
60 return false;
61 }
62
63 ChassisId otherChassisId = (ChassisId) other;
64
65 return value == otherChassisId.value;
66 }
67
68 @Override
69 public int hashCode() {
70 int hash = 17;
71 hash += 31 * hash + (int) (value ^ value >>> 32);
72 return hash;
73 }
74}