wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 1 | /* |
| 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 Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame] | 16 | |
| 17 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 18 | |
Brian O'Connor | 2bed5ce | 2015-06-25 15:10:28 -0400 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Representation of a Tunnel Id. |
| 23 | */ |
Brian O'Connor | 2bed5ce | 2015-06-25 15:10:28 -0400 | [diff] [blame] | 24 | @Beta |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 25 | public 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) { |
samuel | 7a5691a | 2015-05-23 00:36:32 +0800 | [diff] [blame] | 39 | return new TunnelId(Long.parseLong(value)); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 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 SHIMIZU | 8711451 | 2015-05-08 14:31:00 -0700 | [diff] [blame] | 69 | return Long.hashCode(value); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 70 | } |
| 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 | } |