tom | c1a38d3 | 2014-08-25 23:01:32 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.provider; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 2 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 5 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 6 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 7 | /** |
| 8 | * Notion of provider identity. |
| 9 | */ |
| 10 | public class ProviderId { |
| 11 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 12 | private final String scheme; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 13 | private final String id; |
| 14 | |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 15 | // Default constructor for serialization |
| 16 | protected ProviderId() { |
| 17 | scheme = null; |
| 18 | id = null; |
| 19 | } |
| 20 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 21 | /** |
| 22 | * Creates a new provider identifier from the specified string. |
| 23 | * The providers are expected to follow the reverse DNS convention, e.g. |
| 24 | * {@code org.onlab.onos.provider.of.device} |
| 25 | * |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 26 | * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp" |
| 27 | * @param id string identifier |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 28 | */ |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 29 | public ProviderId(String scheme, String id) { |
| 30 | this.scheme = scheme; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 31 | this.id = id; |
| 32 | } |
| 33 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Returns the device URI scheme to which this provider is bound. |
| 36 | * |
| 37 | * @return device URI scheme |
| 38 | */ |
| 39 | public String scheme() { |
| 40 | return scheme; |
| 41 | } |
| 42 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 43 | @Override |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 44 | public int hashCode() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 45 | return Objects.hash(scheme, id); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 49 | public boolean equals(Object obj) { |
| 50 | if (this == obj) { |
| 51 | return true; |
| 52 | } |
| 53 | if (obj == null || getClass() != obj.getClass()) { |
| 54 | return false; |
| 55 | } |
| 56 | final ProviderId other = (ProviderId) obj; |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 57 | return Objects.equals(this.scheme, other.scheme) && |
| 58 | Objects.equals(this.id, other.id); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public String toString() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 63 | return toStringHelper(this).add("scheme", scheme).add("id", id).toString(); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 64 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 65 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 66 | } |