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) {
51 if (getClass() != obj.getClass()) {
54 IPHostId other = (IPHostId) obj;
55 if (ipAddress == null) {
56 if (other.ipAddress != null) {
59 } else if (!ipAddress.equals(other.ipAddress)) {
65 public static IHostId fromIP(InetAddress addr) {
66 return new IPHostId(addr);
72 * @see java.lang.Object#toString()
75 public String toString() {
76 StringBuilder builder = new StringBuilder();
77 builder.append("IP=[");
78 if (this.ipAddress != null) {
79 builder.append(this.ipAddress.getHostAddress());
82 return (builder.toString());