Merge "Move adsal into its own subdirectory."
[controller.git] / opendaylight / adsal / hosttracker / api / src / main / java / org / opendaylight / controller / hosttracker / IPHostId.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.hosttracker;
9
10 import java.io.Serializable;
11 import java.net.InetAddress;
12
13 /*
14  * IP only key class implementation using the marker interface IHostId
15  * @author Deepak Udapudi
16  */
17
18 public class IPHostId implements IHostId, Serializable {
19     private static final long serialVersionUID = 1L;
20     private InetAddress ipAddress;
21
22     public InetAddress getIpAddress() {
23         return ipAddress;
24     }
25
26     public void setIpAddress(InetAddress ipAddress) {
27         this.ipAddress = ipAddress;
28     }
29
30     public IPHostId(InetAddress ipAddress) {
31         super();
32         this.ipAddress = ipAddress;
33     }
34
35     @Override
36     public int hashCode() {
37         final int prime = 31;
38         int result = 1;
39         result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
40         return result;
41     }
42
43     @Override
44     public boolean equals(Object obj) {
45         if (this == obj)
46             return true;
47         if (obj == null)
48             return false;
49         if (getClass() != obj.getClass())
50             return false;
51         IPHostId other = (IPHostId) obj;
52         if (ipAddress == null) {
53             if (other.ipAddress != null)
54                 return false;
55         } else if (!ipAddress.equals(other.ipAddress))
56             return false;
57         return true;
58     }
59
60     public static IHostId fromIP(InetAddress addr) {
61         return new IPHostId(addr);
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see java.lang.Object#toString()
68      */
69     @Override
70     public String toString() {
71         StringBuilder builder = new StringBuilder();
72         builder.append("IP=[");
73         if (this.ipAddress != null) {
74             builder.append(this.ipAddress.getHostAddress());
75         }
76         builder.append("]");
77         return (builder.toString());
78     }
79 }