2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.hosttracker;
10 import java.io.Serializable;
11 import java.net.InetAddress;
14 * IP only key class implementation using the marker interface IHostId
15 * @author Deepak Udapudi
18 public class IPHostId implements IHostId, Serializable {
19 private static final long serialVersionUID = 1L;
20 private InetAddress ipAddress;
22 public InetAddress getIpAddress() {
26 public void setIpAddress(InetAddress ipAddress) {
27 this.ipAddress = ipAddress;
30 public IPHostId(InetAddress ipAddress) {
32 this.ipAddress = ipAddress;
36 public int hashCode() {
39 result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
44 public boolean equals(Object obj) {
49 if (getClass() != obj.getClass())
51 IPHostId other = (IPHostId) obj;
52 if (ipAddress == null) {
53 if (other.ipAddress != null)
55 } else if (!ipAddress.equals(other.ipAddress))
60 public static IHostId fromIP(InetAddress addr) {
61 return new IPHostId(addr);
67 * @see java.lang.Object#toString()
70 public String toString() {
71 StringBuilder builder = new StringBuilder();
72 builder.append("IP=[");
73 if (this.ipAddress != null) {
74 builder.append(this.ipAddress.getHostAddress());
77 return (builder.toString());