blob: c8f117607594cc6bcbbde7dacf5434fb842838ff [file] [log] [blame]
Hyunsun Moon699f46b2015-12-04 11:35:25 -08001/*
2 * Copyright 2014-2015 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 */
16package org.onosproject.cordvtn;
17
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080022import static com.google.common.base.Preconditions.checkNotNull;
23
Hyunsun Moon699f46b2015-12-04 11:35:25 -080024/**
25 * Representation of service identifier.
26 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080027public final class CordServiceId {
Hyunsun Moon699f46b2015-12-04 11:35:25 -080028
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080029 private final String id;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080030
31 /**
32 * Default constructor.
33 *
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080034 * @param id service identifier
Hyunsun Moon699f46b2015-12-04 11:35:25 -080035 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080036 private CordServiceId(String id) {
37 this.id = id;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080038 }
39
40 /**
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080041 * Returns the CordServiceId with value.
Hyunsun Moon699f46b2015-12-04 11:35:25 -080042 *
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080043 * @param id service id
44 * @return CordServiceId
Hyunsun Moon699f46b2015-12-04 11:35:25 -080045 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080046 public static CordServiceId of(String id) {
47 checkNotNull(id);
48 return new CordServiceId(id);
Hyunsun Moon699f46b2015-12-04 11:35:25 -080049 }
50
51 /**
52 * Returns service identifier.
53 *
54 * @return service id
55 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080056 public String id() {
57 return id;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080058 }
59
60 @Override
61 public int hashCode() {
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080062 return Objects.hash(id);
Hyunsun Moon699f46b2015-12-04 11:35:25 -080063 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080070 if (!(obj instanceof CordServiceId)) {
Hyunsun Moon699f46b2015-12-04 11:35:25 -080071 return false;
72 }
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080073 final CordServiceId other = (CordServiceId) obj;
74 return Objects.equals(this.id, other.id);
Hyunsun Moon699f46b2015-12-04 11:35:25 -080075 }
76
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(this)
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080080 .add("id", id)
Hyunsun Moon699f46b2015-12-04 11:35:25 -080081 .toString();
82 }
83}