Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 16 | package org.onlab.packet; |
| 17 | |
| 18 | /** |
| 19 | * The class representing a network device chassisId. |
| 20 | * This class is immutable. |
| 21 | */ |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 22 | public 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 HIGUCHI | e5ca93b | 2014-10-23 09:49:00 -0700 | [diff] [blame] | 49 | this.value = Long.parseLong(value, 16); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 50 | } |
| 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 SHIMIZU | 8711451 | 2015-05-08 14:31:00 -0700 | [diff] [blame] | 84 | return Long.hashCode(value); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 85 | } |
| 86 | } |