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 | |||||
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 15 | /** |
16 | * Creates a new provider identifier from the specified string. | ||||
17 | * The providers are expected to follow the reverse DNS convention, e.g. | ||||
18 | * {@code org.onlab.onos.provider.of.device} | ||||
19 | * | ||||
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 20 | * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp" |
21 | * @param id string identifier | ||||
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 22 | */ |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 23 | public ProviderId(String scheme, String id) { |
24 | this.scheme = scheme; | ||||
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 25 | this.id = id; |
26 | } | ||||
27 | |||||
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 28 | /** |
29 | * Returns the device URI scheme to which this provider is bound. | ||||
30 | * | ||||
31 | * @return device URI scheme | ||||
32 | */ | ||||
33 | public String scheme() { | ||||
34 | return scheme; | ||||
35 | } | ||||
36 | |||||
Yuta HIGUCHI | c705201 | 2014-09-22 19:11:00 -0700 | [diff] [blame^] | 37 | /** |
38 | * Returns the device URI scheme specific id portion. | ||||
39 | * | ||||
40 | * @return id | ||||
41 | */ | ||||
42 | public String id() { | ||||
43 | return id; | ||||
44 | } | ||||
45 | |||||
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 46 | @Override |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 47 | public int hashCode() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 48 | return Objects.hash(scheme, id); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 49 | } |
50 | |||||
51 | @Override | ||||
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 52 | public boolean equals(Object obj) { |
53 | if (this == obj) { | ||||
54 | return true; | ||||
55 | } | ||||
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 56 | if (obj instanceof ProviderId) { |
57 | final ProviderId other = (ProviderId) obj; | ||||
58 | return Objects.equals(this.scheme, other.scheme) && | ||||
59 | Objects.equals(this.id, other.id); | ||||
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 60 | } |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 61 | return false; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 62 | } |
63 | |||||
64 | @Override | ||||
65 | public String toString() { | ||||
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 66 | return toStringHelper(this).add("scheme", scheme).add("id", id).toString(); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 67 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 68 | |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 69 | } |