blob: d5994863d673e55a5414f9c6349bc0fbc9346929 [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;
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040020
21import com.google.common.annotations.Beta;
wei wei89ddc322015-03-22 16:29:04 -050022import com.google.common.primitives.UnsignedLongs;
23
24/**
25 * Representation of a label Id, a logical port identifier.
26 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040027@Beta
jcc4a20a5f2015-04-30 15:43:39 +080028public final class OpticalLogicId {
wei wei89ddc322015-03-22 16:29:04 -050029 /**
30 * Represents a logical Id.
31 */
jcc4a20a5f2015-04-30 15:43:39 +080032 private final long logicId;
wei wei89ddc322015-03-22 16:29:04 -050033
34 /**
35 * Constructor, public creation is prohibited.
36 */
jcc4a20a5f2015-04-30 15:43:39 +080037 private OpticalLogicId(long id) {
38 this.logicId = id;
wei wei89ddc322015-03-22 16:29:04 -050039 }
40
41 /**
42 * Returns the LabelId representing the specified long value.
43 *
44 * @param id identifier as long value
45 * @return LabelId
46 */
jcc4a20a5f2015-04-30 15:43:39 +080047 public static OpticalLogicId logicId(long id) {
48 return new OpticalLogicId(id);
wei wei89ddc322015-03-22 16:29:04 -050049 }
50
jcc4a20a5f2015-04-30 15:43:39 +080051 public static OpticalLogicId logicId(String string) {
52 return new OpticalLogicId(UnsignedLongs.decode(string));
wei wei89ddc322015-03-22 16:29:04 -050053 }
54
55 public long toLong() {
jcc4a20a5f2015-04-30 15:43:39 +080056 return logicId;
wei wei89ddc322015-03-22 16:29:04 -050057 }
58
59 @Override
60 public String toString() {
jcc4a20a5f2015-04-30 15:43:39 +080061 return UnsignedLongs.toString(logicId);
wei wei89ddc322015-03-22 16:29:04 -050062 }
63
64 @Override
65 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070066 return Objects.hashCode(logicId);
wei wei89ddc322015-03-22 16:29:04 -050067 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
jcc4a20a5f2015-04-30 15:43:39 +080074 if (obj instanceof OpticalLogicId) {
75 final OpticalLogicId other = (OpticalLogicId) obj;
76 return this.logicId == other.logicId;
wei wei89ddc322015-03-22 16:29:04 -050077 }
78 return false;
79 }
80
81}