blob: 85a374630e402b283c22bcda23d20311ed7e423b [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 */
22// TODO: Move this to a reasonable place.
23public final class ChassisId {
24
25 private static final long UNKNOWN = 0;
26 private final long value;
27
28 /**
29 * Default constructor.
30 */
31 public ChassisId() {
32 this.value = ChassisId.UNKNOWN;
33 }
34
35 /**
36 * Constructor from a long value.
37 *
38 * @param value the value to use.
39 */
40 public ChassisId(long value) {
41 this.value = value;
42 }
43
44 /**
45 * Constructor from a string.
46 *
47 * @param value the value to use.
48 */
49 public ChassisId(String value) {
Yuta HIGUCHIe5ca93b2014-10-23 09:49:00 -070050 this.value = Long.parseLong(value, 16);
alshabib7911a052014-10-16 17:49:37 -070051 }
52
53 /**
54 * Get the value of the chassis id.
55 *
56 * @return the value of the chassis id.
57 */
58 public long value() {
59 return value;
60 }
61
62 /**
63 * Convert the Chassis Id value to a ':' separated hexadecimal string.
64 *
65 * @return the Chassis Id value as a ':' separated hexadecimal string.
66 */
67 @Override
68 public String toString() {
69 return Long.toHexString(this.value);
70 }
71
72 @Override
73 public boolean equals(Object other) {
74 if (!(other instanceof ChassisId)) {
75 return false;
76 }
77
78 ChassisId otherChassisId = (ChassisId) other;
79
80 return value == otherChassisId.value;
81 }
82
83 @Override
84 public int hashCode() {
85 int hash = 17;
86 hash += 31 * hash + (int) (value ^ value >>> 32);
87 return hash;
88 }
89}