blob: adaa82b6441a00f2ac2390ffea29c0daa5c82a8a [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 */
Phanendra Manda37b97fb2015-08-15 02:04:24 +053016package org.onosproject.net;
17
18import java.util.Objects;
19import org.onlab.packet.IpAddress;
20import com.google.common.base.MoreObjects;
21
22/**
23 * Represent for a Element ID using ip address.
24 */
25public final class IpElementId extends ElementId {
26
27 private final IpAddress ipAddress;
28
29 /**
30 * Public construction is prohibited.
31 * @param ipAddress ip address
32 */
33 private IpElementId(IpAddress ipAddress) {
34 this.ipAddress = ipAddress;
35 }
36
37 /**
38 * Create a IP Element ID.
39 * @param ipAddress IP address
40 * @return IpElementId
41 */
42 public static IpElementId ipElement(IpAddress ipAddress) {
43 return new IpElementId(ipAddress);
44 }
45
46 /**
47 * Returns the ip address.
48 *
49 * @return ipAddress
50 */
51 public IpAddress ipAddress() {
52 return ipAddress;
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(ipAddress);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj instanceof IpElementId) {
66 final IpElementId other = (IpElementId) obj;
67 return Objects.equals(this.ipAddress, other.ipAddress);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return MoreObjects.toStringHelper(getClass()).add("ipAddress", ipAddress).toString();
75 }
76}