blob: d396c0d180e5c2914028495941d4e4c6fe00fb3e [file] [log] [blame]
bobzhou1aaecbd2015-10-31 17:41:34 +08001/*
2 * Copyright 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.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
24 * Immutable representation of a router identifier.
25 */
26public final class RouterId {
27
28 private final String routerId;
29
30 // Public construction is prohibited
31 private RouterId(String routerId) {
32 checkNotNull(routerId, "routerId cannot be null");
33 this.routerId = routerId;
34 }
35
36 /**
37 * Creates a router identifier.
38 *
39 * @param routerId the router identifier
40 * @return the router identifier
41 */
42 public static RouterId valueOf(String routerId) {
43 return new RouterId(routerId);
44 }
45
46 /**
47 * Returns the router identifier.
48 *
49 * @return the router identifier
50 */
51 public String routerId() {
52 return routerId;
53 }
54
55 @Override
56 public int hashCode() {
57 return routerId.hashCode();
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj instanceof RouterId) {
66 final RouterId that = (RouterId) obj;
67 return Objects.equals(this.routerId, that.routerId);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return toStringHelper(this).add("routerId", routerId).toString();
75 }
76}
77