blob: 725748ab08a06495694cea1f1b1e0937df40ee8c [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
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070037 /**
38 * Returns the device URI scheme specific id portion.
39 *
40 * @return id
41 */
42 public String id() {
43 return id;
44 }
45
tom0eb04ca2014-08-25 14:34:51 -070046 @Override
tom64b7aac2014-08-26 00:18:21 -070047 public int hashCode() {
tom7e02cda2014-09-18 12:05:46 -070048 return Objects.hash(scheme, id);
tom0eb04ca2014-08-25 14:34:51 -070049 }
50
51 @Override
tom64b7aac2014-08-26 00:18:21 -070052 public boolean equals(Object obj) {
53 if (this == obj) {
54 return true;
55 }
tomfc9a4ff2014-09-22 18:22:47 -070056 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);
tom64b7aac2014-08-26 00:18:21 -070060 }
tomfc9a4ff2014-09-22 18:22:47 -070061 return false;
tom0eb04ca2014-08-25 14:34:51 -070062 }
63
64 @Override
65 public String toString() {
tom7e02cda2014-09-18 12:05:46 -070066 return toStringHelper(this).add("scheme", scheme).add("id", id).toString();
tom0eb04ca2014-08-25 14:34:51 -070067 }
tom64b7aac2014-08-26 00:18:21 -070068
tom0eb04ca2014-08-25 14:34:51 -070069}