alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 1 | package 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. |
| 8 | public 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 Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 35 | this.value = Long.valueOf(value, 16); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 36 | } |
| 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 | } |