blob: a3de7883ba5a447c60ce73eaba9f3cc0cb46921d [file] [log] [blame]
Aaron Kruglikovb4916d02015-09-08 16:22:25 -07001/*
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
17package org.onosproject.incubator.net.tunnel;
18
19import com.google.common.annotations.Beta;
20
21/**
22 * Representation of a Network Tunnel Id.
23 */
24@Beta
25public final class NetworkTunnelId {
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 NetworkTunnelId valueOf(long value) {
35 return new NetworkTunnelId(value);
36 }
37
38 public static NetworkTunnelId valueOf(String value) {
39 return new NetworkTunnelId(Long.parseLong(value));
40 }
41
42 /**
43 * Constructor for serializer.
44 */
45 NetworkTunnelId() {
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 public NetworkTunnelId(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() {
69 return Long.hashCode(value);
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (obj == this) {
75 return true;
76 }
77 if (!(obj instanceof NetworkTunnelId)) {
78 return false;
79 }
80 NetworkTunnelId that = (NetworkTunnelId) obj;
81 return this.value == that.value;
82 }
83
84 @Override
85 public String toString() {
86 return "0x" + Long.toHexString(value);
87 }
88
89}