blob: 56035c02e9118613eab107094e1e624d4cfbe2eb [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Satish Kf6d87cb2015-11-30 19:59:22 +05303 *
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 *
Jian Lidfba7392016-01-22 16:46:58 -080032 * @param routerId Router ID of designated router
33 * @param type protocol type
Satish Kf6d87cb2015-11-30 19:59:22 +053034 */
35 public RouterId(int routerId, ProtocolType type) {
36 this.routerId = routerId;
37 this.type = type;
38 }
39
40 /**
41 * Obtains Router Id of the device.
42 *
43 * @return Router Id of the device
44 */
45 public int routerId() {
46 return routerId;
47 }
48
49 @Override
50 public ProtocolType type() {
51 return type;
52 }
53
54 @Override
55 public int hashCode() {
56 return Objects.hash(routerId, type);
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64
65 if (obj instanceof RouterId) {
66 RouterId other = (RouterId) obj;
67 return Objects.equals(routerId, other.routerId) && Objects.equals(type, other.type);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return toStringHelper(this)
75 .add("routerId", routerId)
76 .add("type", type)
77 .toString();
78 }
79}