blob: 0cbad8c10e417bba0f7d9cf86b5ebe58326f160d [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
wei wei89ddc322015-03-22 16:29:04 -050019
20/**
21 * Representation of a Tunnel Id.
22 */
23public final class TunnelId {
24 private final long value;
25
26 /**
27 * Creates an tunnel identifier from the specified tunnel.
28 *
29 * @param value long value
30 * @return tunnel identifier
31 */
32 public static TunnelId valueOf(long value) {
33 return new TunnelId(value);
34 }
35
36 public static TunnelId valueOf(String value) {
samuel7a5691a2015-05-23 00:36:32 +080037 return new TunnelId(Long.parseLong(value));
wei wei89ddc322015-03-22 16:29:04 -050038 }
39
40 /**
41 * Constructor for serializer.
42 */
43 TunnelId() {
44 this.value = 0;
45 }
46
47 /**
48 * Constructs the ID corresponding to a given long value.
49 *
50 * @param value the underlying value of this ID
51 */
52 TunnelId(long value) {
53 this.value = value;
54 }
55
56 /**
57 * Returns the backing value.
58 *
59 * @return the value
60 */
61 public long id() {
62 return value;
63 }
64
65 @Override
66 public int hashCode() {
Sho SHIMIZU87114512015-05-08 14:31:00 -070067 return Long.hashCode(value);
wei wei89ddc322015-03-22 16:29:04 -050068 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (obj == this) {
73 return true;
74 }
75 if (!(obj instanceof TunnelId)) {
76 return false;
77 }
78 TunnelId that = (TunnelId) obj;
79 return this.value == that.value;
80 }
81
82 @Override
83 public String toString() {
84 return "0x" + Long.toHexString(value);
85 }
86
87}