blob: 23c9859ffe5a472f6bbd4ecb280a3bc4d409076a [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
alshabib7911a052014-10-16 17:49:37 -070016package org.onlab.packet;
17
18/**
19 * The class representing a network device chassisId.
20 * This class is immutable.
21 */
alshabib7911a052014-10-16 17:49:37 -070022public final class ChassisId {
23
24 private static final long UNKNOWN = 0;
25 private final long value;
26
27 /**
28 * Default constructor.
29 */
30 public ChassisId() {
31 this.value = ChassisId.UNKNOWN;
32 }
33
34 /**
35 * Constructor from a long value.
36 *
37 * @param value the value to use.
38 */
39 public ChassisId(long value) {
40 this.value = value;
41 }
42
43 /**
44 * Constructor from a string.
45 *
46 * @param value the value to use.
47 */
48 public ChassisId(String value) {
Yuta HIGUCHIe5ca93b2014-10-23 09:49:00 -070049 this.value = Long.parseLong(value, 16);
alshabib7911a052014-10-16 17:49:37 -070050 }
51
52 /**
53 * Get the value of the chassis id.
54 *
55 * @return the value of the chassis id.
56 */
57 public long value() {
58 return value;
59 }
60
61 /**
62 * Convert the Chassis Id value to a ':' separated hexadecimal string.
63 *
64 * @return the Chassis Id value as a ':' separated hexadecimal string.
65 */
66 @Override
67 public String toString() {
68 return Long.toHexString(this.value);
69 }
70
71 @Override
72 public boolean equals(Object other) {
73 if (!(other instanceof ChassisId)) {
74 return false;
75 }
76
77 ChassisId otherChassisId = (ChassisId) other;
78
79 return value == otherChassisId.value;
80 }
81
82 @Override
83 public int hashCode() {
Sho SHIMIZU87114512015-05-08 14:31:00 -070084 return Long.hashCode(value);
alshabib7911a052014-10-16 17:49:37 -070085 }
86}