wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame^] | 16 | |
| 17 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 18 | |
| 19 | import java.util.Objects; |
| 20 | import com.google.common.primitives.UnsignedLongs; |
| 21 | |
| 22 | /** |
| 23 | * Representation of a label Id, a logical port identifier. |
| 24 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 25 | public final class OpticalLogicId { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 26 | /** |
| 27 | * Represents a logical Id. |
| 28 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 29 | private final long logicId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Constructor, public creation is prohibited. |
| 33 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 34 | private OpticalLogicId(long id) { |
| 35 | this.logicId = id; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns the LabelId representing the specified long value. |
| 40 | * |
| 41 | * @param id identifier as long value |
| 42 | * @return LabelId |
| 43 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 44 | public static OpticalLogicId logicId(long id) { |
| 45 | return new OpticalLogicId(id); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 46 | } |
| 47 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 48 | public static OpticalLogicId logicId(String string) { |
| 49 | return new OpticalLogicId(UnsignedLongs.decode(string)); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | public long toLong() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 53 | return logicId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String toString() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 58 | return UnsignedLongs.toString(logicId); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public int hashCode() { |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 63 | return Objects.hash(logicId); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public boolean equals(Object obj) { |
| 68 | if (this == obj) { |
| 69 | return true; |
| 70 | } |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 71 | if (obj instanceof OpticalLogicId) { |
| 72 | final OpticalLogicId other = (OpticalLogicId) obj; |
| 73 | return this.logicId == other.logicId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 74 | } |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | } |