Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 19 | package org.onlab.packet; |
| 20 | |
| 21 | /** |
| 22 | * The class representing a network device chassisId. |
| 23 | * This class is immutable. |
| 24 | */ |
| 25 | // TODO: Move this to a reasonable place. |
| 26 | public final class ChassisId { |
| 27 | |
| 28 | private static final long UNKNOWN = 0; |
| 29 | private final long value; |
| 30 | |
| 31 | /** |
| 32 | * Default constructor. |
| 33 | */ |
| 34 | public ChassisId() { |
| 35 | this.value = ChassisId.UNKNOWN; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Constructor from a long value. |
| 40 | * |
| 41 | * @param value the value to use. |
| 42 | */ |
| 43 | public ChassisId(long value) { |
| 44 | this.value = value; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Constructor from a string. |
| 49 | * |
| 50 | * @param value the value to use. |
| 51 | */ |
| 52 | public ChassisId(String value) { |
Yuta HIGUCHI | e5ca93b | 2014-10-23 09:49:00 -0700 | [diff] [blame] | 53 | this.value = Long.parseLong(value, 16); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the value of the chassis id. |
| 58 | * |
| 59 | * @return the value of the chassis id. |
| 60 | */ |
| 61 | public long value() { |
| 62 | return value; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Convert the Chassis Id value to a ':' separated hexadecimal string. |
| 67 | * |
| 68 | * @return the Chassis Id value as a ':' separated hexadecimal string. |
| 69 | */ |
| 70 | @Override |
| 71 | public String toString() { |
| 72 | return Long.toHexString(this.value); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object other) { |
| 77 | if (!(other instanceof ChassisId)) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | ChassisId otherChassisId = (ChassisId) other; |
| 82 | |
| 83 | return value == otherChassisId.value; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public int hashCode() { |
| 88 | int hash = 17; |
| 89 | hash += 31 * hash + (int) (value ^ value >>> 32); |
| 90 | return hash; |
| 91 | } |
| 92 | } |