samuel | 8d6b0a9 | 2015-07-11 13:22:57 +0800 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.net.behaviour; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * Represents for a unique tunnel name. TunnelId is generated by ONOS while |
| 25 | * TunnelName is given by producer. The consumer can borrow tunnels with |
| 26 | * TunnelId or TunnelName. |
| 27 | */ |
| 28 | @Beta |
| 29 | public final class TunnelName { |
| 30 | private final String str; |
| 31 | |
| 32 | // Default constructor for serialization |
| 33 | private TunnelName(String tunnelName) { |
| 34 | this.str = tunnelName; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Creates a tunnel name using the supplied URI string. |
| 40 | * |
| 41 | * @param tunnelName tunnel name string |
| 42 | * @return tunnel name object |
| 43 | */ |
| 44 | public static TunnelName tunnelName(String tunnelName) { |
| 45 | return new TunnelName(tunnelName); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * The string of tunnel name. |
| 50 | * |
| 51 | * @return the string of tunnel name |
| 52 | */ |
| 53 | public String value() { |
| 54 | return str; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hash(str); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object obj) { |
| 64 | if (this == obj) { |
| 65 | return true; |
| 66 | } |
| 67 | if (obj instanceof TunnelName) { |
| 68 | final TunnelName that = (TunnelName) obj; |
| 69 | return this.getClass() == that.getClass() |
| 70 | && Objects.equals(this.str, that.str); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public String toString() { |
| 77 | return str; |
| 78 | } |
| 79 | } |