jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 1 | package org.onosproject.net.tunnel; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | /** |
| 6 | * Represents for a unique tunnel name. TunnelId is generated by ONOS while |
| 7 | * TunnelName is given by producer. The consumer can borrow tunnels with |
| 8 | * TunnelId or TunnelName. |
| 9 | */ |
| 10 | public final class TunnelName { |
| 11 | private final String str; |
| 12 | |
| 13 | // Default constructor for serialization |
| 14 | private TunnelName(String tunnelName) { |
| 15 | this.str = tunnelName; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * Creates a tunnel name using the supplied URI string. |
| 21 | * |
| 22 | * @param tunnelName tunnel name string |
| 23 | * @return tunnel name object |
| 24 | */ |
| 25 | public static TunnelName tunnelName(String tunnelName) { |
| 26 | return new TunnelName(tunnelName); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * The string of tunnel name. |
| 31 | * |
| 32 | * @return the string of tunnel name |
| 33 | */ |
| 34 | public String value() { |
| 35 | return str; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public int hashCode() { |
| 40 | return Objects.hash(str); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public boolean equals(Object obj) { |
| 45 | if (this == obj) { |
| 46 | return true; |
| 47 | } |
| 48 | if (obj instanceof TunnelName) { |
| 49 | final TunnelName that = (TunnelName) obj; |
| 50 | return this.getClass() == that.getClass() |
| 51 | && Objects.equals(this.str, that.str); |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String toString() { |
| 58 | return str; |
| 59 | } |
| 60 | } |