blob: fee5542d82e9a5e305c6f89c2f6ebad5d9ddf28a [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 */
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070016
17package org.onosproject.incubator.net.tunnel;
wei wei89ddc322015-03-22 16:29:04 -050018
19import java.util.Objects;
20import com.google.common.primitives.UnsignedLongs;
21
22/**
23 * Representation of a label Id, a logical port identifier.
24 */
jcc4a20a5f2015-04-30 15:43:39 +080025public final class OpticalLogicId {
wei wei89ddc322015-03-22 16:29:04 -050026 /**
27 * Represents a logical Id.
28 */
jcc4a20a5f2015-04-30 15:43:39 +080029 private final long logicId;
wei wei89ddc322015-03-22 16:29:04 -050030
31 /**
32 * Constructor, public creation is prohibited.
33 */
jcc4a20a5f2015-04-30 15:43:39 +080034 private OpticalLogicId(long id) {
35 this.logicId = id;
wei wei89ddc322015-03-22 16:29:04 -050036 }
37
38 /**
39 * Returns the LabelId representing the specified long value.
40 *
41 * @param id identifier as long value
42 * @return LabelId
43 */
jcc4a20a5f2015-04-30 15:43:39 +080044 public static OpticalLogicId logicId(long id) {
45 return new OpticalLogicId(id);
wei wei89ddc322015-03-22 16:29:04 -050046 }
47
jcc4a20a5f2015-04-30 15:43:39 +080048 public static OpticalLogicId logicId(String string) {
49 return new OpticalLogicId(UnsignedLongs.decode(string));
wei wei89ddc322015-03-22 16:29:04 -050050 }
51
52 public long toLong() {
jcc4a20a5f2015-04-30 15:43:39 +080053 return logicId;
wei wei89ddc322015-03-22 16:29:04 -050054 }
55
56 @Override
57 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +080058 return UnsignedLongs.toString(logicId);
wei wei89ddc322015-03-22 16:29:04 -050059 }
60
61 @Override
62 public int hashCode() {
jcc4a20a5f2015-04-30 15:43:39 +080063 return Objects.hash(logicId);
wei wei89ddc322015-03-22 16:29:04 -050064 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (this == obj) {
69 return true;
70 }
jcc4a20a5f2015-04-30 15:43:39 +080071 if (obj instanceof OpticalLogicId) {
72 final OpticalLogicId other = (OpticalLogicId) obj;
73 return this.logicId == other.logicId;
wei wei89ddc322015-03-22 16:29:04 -050074 }
75 return false;
76 }
77
78}