Fix checkstyle if-statements must use braces hosttracker
[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         }
48         if (obj == null) {
49             return false;
50         }
51         if (getClass() != obj.getClass()) {
52             return false;
53         }
54         IPHostId other = (IPHostId) obj;
55         if (ipAddress == null) {
56             if (other.ipAddress != null) {
57                 return false;
58             }
59         } else if (!ipAddress.equals(other.ipAddress)) {
60             return false;
61         }
62         return true;
63     }
64
65     public static IHostId fromIP(InetAddress addr) {
66         return new IPHostId(addr);
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see java.lang.Object#toString()
73      */
74     @Override
75     public String toString() {
76         StringBuilder builder = new StringBuilder();
77         builder.append("IP=[");
78         if (this.ipAddress != null) {
79             builder.append(this.ipAddress.getHostAddress());
80         }
81         builder.append("]");
82         return (builder.toString());
83     }
84 }