blob: 85714cb12facf89e67be0f6d8a136828a6526c7f [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
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.iptopology.api;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21
22/**
23 * Represents Router ID of the device.
24 */
25public class RouterId implements RouteIdentifier {
26 private final int routerId;
27 private final ProtocolType type;
28
29 /**
30 * Constructor to initialize its parameters.
31 *
32 * @param routerId Router ID of designated router
33 */
34 public RouterId(int routerId, ProtocolType type) {
35 this.routerId = routerId;
36 this.type = type;
37 }
38
39 /**
40 * Obtains Router Id of the device.
41 *
42 * @return Router Id of the device
43 */
44 public int routerId() {
45 return routerId;
46 }
47
48 @Override
49 public ProtocolType type() {
50 return type;
51 }
52
53 @Override
54 public int hashCode() {
55 return Objects.hash(routerId, type);
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (this == obj) {
61 return true;
62 }
63
64 if (obj instanceof RouterId) {
65 RouterId other = (RouterId) obj;
66 return Objects.equals(routerId, other.routerId) && Objects.equals(type, other.type);
67 }
68 return false;
69 }
70
71 @Override
72 public String toString() {
73 return toStringHelper(this)
74 .add("routerId", routerId)
75 .add("type", type)
76 .toString();
77 }
78}