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