blob: 5a3f97f25a6eb0b0494311555b870b6931ccb032 [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
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040019import com.google.common.annotations.Beta;
wei wei89ddc322015-03-22 16:29:04 -050020
21/**
22 * Representation of a Tunnel Id.
23 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040024@Beta
wei wei89ddc322015-03-22 16:29:04 -050025public final class TunnelId {
26 private final long value;
27
28 /**
29 * Creates an tunnel identifier from the specified tunnel.
30 *
31 * @param value long value
32 * @return tunnel identifier
33 */
34 public static TunnelId valueOf(long value) {
35 return new TunnelId(value);
36 }
37
38 public static TunnelId valueOf(String value) {
samuel7a5691a2015-05-23 00:36:32 +080039 return new TunnelId(Long.parseLong(value));
wei wei89ddc322015-03-22 16:29:04 -050040 }
41
42 /**
43 * Constructor for serializer.
44 */
45 TunnelId() {
46 this.value = 0;
47 }
48
49 /**
50 * Constructs the ID corresponding to a given long value.
51 *
52 * @param value the underlying value of this ID
53 */
54 TunnelId(long value) {
55 this.value = value;
56 }
57
58 /**
59 * Returns the backing value.
60 *
61 * @return the value
62 */
63 public long id() {
64 return value;
65 }
66
67 @Override
68 public int hashCode() {
Sho SHIMIZU87114512015-05-08 14:31:00 -070069 return Long.hashCode(value);
wei wei89ddc322015-03-22 16:29:04 -050070 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (obj == this) {
75 return true;
76 }
77 if (!(obj instanceof TunnelId)) {
78 return false;
79 }
80 TunnelId that = (TunnelId) obj;
81 return this.value == that.value;
82 }
83
84 @Override
85 public String toString() {
86 return "0x" + Long.toHexString(value);
87 }
88
89}