blob: fa5332d41259c45624944e0b02c9bb02fe76e4cf [file] [log] [blame]
yoonseone92748c2016-12-13 16:37:51 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.incubator.net.virtual.provider;
18
19import java.util.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22
23public abstract class AbstractVirtualProvider implements VirtualProvider {
24 private final String scheme;
25 private final String id;
26
27 /**
28 * Creates a provider with the supplied identifier.
29 *
30 * @param scheme provider scheme
31 * @param id provider id
32 */
33 protected AbstractVirtualProvider(String id, String scheme) {
34 this.scheme = scheme;
35 this.id = id;
36 }
37
38 /**
39 * Returns the device URI scheme to which this provider is bound.
40 *
41 * @return device URI scheme
42 */
43 @Override
44 public String scheme() {
45 return this.scheme;
46 }
47
48 /**
49 * Returns the device URI scheme specific id portion.
50 *
51 * @return id
52 */
53 @Override
54 public String id() {
55 return this.id;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(scheme, id);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof AbstractVirtualProvider) {
69 final AbstractVirtualProvider other = (AbstractVirtualProvider) obj;
70 return Objects.equals(this.scheme, other.scheme) &&
71 Objects.equals(this.id, other.id);
72 }
73 return false;
74 }
75
76 @Override
77 public String toString() {
78 return toStringHelper(this).add("scheme", scheme).add("id", id)
79 .toString();
80 }
81}