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