90f5eab6f4dc457a27de554a900196014de8d84f
[onosfw.git] /
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  */
16
17 package org.onosproject.incubator.net.tunnel;
18
19 import java.util.Objects;
20
21 import com.google.common.annotations.Beta;
22 import com.google.common.primitives.UnsignedLongs;
23
24 /**
25  * Representation of a label Id, a logical port identifier.
26  */
27 @Beta
28 public final class OpticalLogicId {
29         /**
30          * Represents a logical Id.
31         */
32         private final long logicId;
33
34         /**
35          * Constructor, public creation is prohibited.
36          */
37         private OpticalLogicId(long id) {
38             this.logicId = id;
39         }
40
41         /**
42          * Returns the LabelId representing the specified long value.
43          *
44          * @param id identifier as long value
45          * @return LabelId
46          */
47         public static OpticalLogicId logicId(long id) {
48             return new OpticalLogicId(id);
49         }
50
51         public static OpticalLogicId logicId(String string) {
52             return new OpticalLogicId(UnsignedLongs.decode(string));
53         }
54
55         public long toLong() {
56             return logicId;
57         }
58
59         @Override
60         public String toString() {
61             return UnsignedLongs.toString(logicId);
62         }
63
64         @Override
65         public int hashCode() {
66             return Objects.hash(logicId);
67         }
68
69         @Override
70         public boolean equals(Object obj) {
71             if (this == obj) {
72                 return true;
73             }
74             if (obj instanceof OpticalLogicId) {
75                 final OpticalLogicId other = (OpticalLogicId) obj;
76                 return this.logicId == other.logicId;
77             }
78             return false;
79         }
80
81 }