blob: b596700bfc3d0d620ceec2ba3e0c85bb54603540 [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 static com.google.common.base.Preconditions.checkArgument;
20
21/**
22 * Representation of a Tunnel Id.
23 */
24public final class TunnelId {
25 private final long value;
26
27 /**
28 * Creates an tunnel identifier from the specified tunnel.
29 *
30 * @param value long value
31 * @return tunnel identifier
32 */
33 public static TunnelId valueOf(long value) {
34 return new TunnelId(value);
35 }
36
37 public static TunnelId valueOf(String value) {
38 checkArgument(value.startsWith("0x"));
39 return new TunnelId(Long.parseLong(value.substring("0x".length()), 16));
40 }
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}