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