blob: e9af0eba00a28e49618eb86ead81e96917a40ac3 [file] [log] [blame]
tomc1a38d32014-08-25 23:01:32 -07001package org.onlab.onos.net.provider;
tom0eb04ca2014-08-25 14:34:51 -07002
tom64b7aac2014-08-26 00:18:21 -07003import java.util.Objects;
4
tomeadbb462014-09-07 16:10:19 -07005import static com.google.common.base.MoreObjects.toStringHelper;
tom64b7aac2014-08-26 00:18:21 -07006
tom0eb04ca2014-08-25 14:34:51 -07007/**
8 * Notion of provider identity.
9 */
10public class ProviderId {
11
tom7e02cda2014-09-18 12:05:46 -070012 private final String scheme;
tom0eb04ca2014-08-25 14:34:51 -070013 private final String id;
14
tom64b7aac2014-08-26 00:18:21 -070015 /**
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 *
tom7e02cda2014-09-18 12:05:46 -070020 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
21 * @param id string identifier
tom64b7aac2014-08-26 00:18:21 -070022 */
tom7e02cda2014-09-18 12:05:46 -070023 public ProviderId(String scheme, String id) {
24 this.scheme = scheme;
tom0eb04ca2014-08-25 14:34:51 -070025 this.id = id;
26 }
27
tom7e02cda2014-09-18 12:05:46 -070028 /**
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
tom0eb04ca2014-08-25 14:34:51 -070037 @Override
tom64b7aac2014-08-26 00:18:21 -070038 public int hashCode() {
tom7e02cda2014-09-18 12:05:46 -070039 return Objects.hash(scheme, id);
tom0eb04ca2014-08-25 14:34:51 -070040 }
41
42 @Override
tom64b7aac2014-08-26 00:18:21 -070043 public boolean equals(Object obj) {
44 if (this == obj) {
45 return true;
46 }
47 if (obj == null || getClass() != obj.getClass()) {
48 return false;
49 }
50 final ProviderId other = (ProviderId) obj;
tom7e02cda2014-09-18 12:05:46 -070051 return Objects.equals(this.scheme, other.scheme) &&
52 Objects.equals(this.id, other.id);
tom0eb04ca2014-08-25 14:34:51 -070053 }
54
55 @Override
56 public String toString() {
tom7e02cda2014-09-18 12:05:46 -070057 return toStringHelper(this).add("scheme", scheme).add("id", id).toString();
tom0eb04ca2014-08-25 14:34:51 -070058 }
tom64b7aac2014-08-26 00:18:21 -070059
tom0eb04ca2014-08-25 14:34:51 -070060}