blob: 8d3d57190cc2578e8c8443b488acaf3e2c775eeb [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
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070015 // Default constructor for serialization
16 protected ProviderId() {
17 scheme = null;
18 id = null;
19 }
20
tom64b7aac2014-08-26 00:18:21 -070021 /**
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 *
tom7e02cda2014-09-18 12:05:46 -070026 * @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
27 * @param id string identifier
tom64b7aac2014-08-26 00:18:21 -070028 */
tom7e02cda2014-09-18 12:05:46 -070029 public ProviderId(String scheme, String id) {
30 this.scheme = scheme;
tom0eb04ca2014-08-25 14:34:51 -070031 this.id = id;
32 }
33
tom7e02cda2014-09-18 12:05:46 -070034 /**
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
tom0eb04ca2014-08-25 14:34:51 -070043 @Override
tom64b7aac2014-08-26 00:18:21 -070044 public int hashCode() {
tom7e02cda2014-09-18 12:05:46 -070045 return Objects.hash(scheme, id);
tom0eb04ca2014-08-25 14:34:51 -070046 }
47
48 @Override
tom64b7aac2014-08-26 00:18:21 -070049 public boolean equals(Object obj) {
50 if (this == obj) {
51 return true;
52 }
tomfc9a4ff2014-09-22 18:22:47 -070053 if (obj instanceof ProviderId) {
54 final ProviderId other = (ProviderId) obj;
55 return Objects.equals(this.scheme, other.scheme) &&
56 Objects.equals(this.id, other.id);
tom64b7aac2014-08-26 00:18:21 -070057 }
tomfc9a4ff2014-09-22 18:22:47 -070058 return false;
tom0eb04ca2014-08-25 14:34:51 -070059 }
60
61 @Override
62 public String toString() {
tom7e02cda2014-09-18 12:05:46 -070063 return toStringHelper(this).add("scheme", scheme).add("id", id).toString();
tom0eb04ca2014-08-25 14:34:51 -070064 }
tom64b7aac2014-08-26 00:18:21 -070065
tom0eb04ca2014-08-25 14:34:51 -070066}