blob: 430823caa119cef609c3fb7bdf6d1cb20c07f365 [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
19/**
20 * A wrapper class for a long used to identify domain level tunnels.
21 */
22public final class DomainTunnelId {
23
24 private final long value;
25
26 /**
27 * Creates a tunnel identifier from the specified tunnel.
28 *
29 * @param value long value
30 * @return domain tunnel identifier
31 */
32 public static DomainTunnelId valueOf(long value) {
33 return new DomainTunnelId(value);
34 }
35
36 /**
37 * Creates a tunnel identifier from the specified tunnel.
38 *
39 * @param value long value as a string
40 * @return domain tunnel identifier
41 */
42 public static DomainTunnelId valueOf(String value) {
43 return new DomainTunnelId(Long.parseLong(value));
44 }
45
46 /**
47 * Constructor for serializer.
48 */
49 protected DomainTunnelId() {
50 this.value = 0;
51 }
52
53 /**
54 * Constructs the Domain ID corresponding to a given long value.
55 *
56 * @param value the underlying value of this domain ID
57 */
58 public DomainTunnelId(long value) {
59 this.value = value;
60 }
61
62 /**
63 * Returns the backing value of this domain ID.
64 *
65 * @return the long value
66 */
67 public long id() {
68 return value;
69 }
70
71 @Override
72 public int hashCode() {
73 return Long.hashCode(value);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (obj == this) {
79 return true;
80 }
81 if (!(obj instanceof DomainTunnelId)) {
82 return false;
83 }
84 DomainTunnelId that = (DomainTunnelId) obj;
85 return this.value == that.value;
86 }
87
88 @Override
89 public String toString() {
90 return "0x" + Long.toHexString(value);
91 }
92}