blob: d6a87b5e169f74423de1136d6d0bf1c431ea034d [file] [log] [blame]
Madan Jampaniab6d3112014-10-02 16:30:14 -07001package org.onlab.netty;
2
3/**
4 * Representation of a TCP/UDP communication end point.
5 */
6public class Endpoint {
7
8 private final int port;
9 private final String host;
10
Madan Jampani86ed0552014-10-03 16:45:42 -070011 /**
12 * Used for serialization.
13 */
Madan Jampani938aa432014-10-04 17:37:23 -070014 @SuppressWarnings("unused")
Madan Jampani86ed0552014-10-03 16:45:42 -070015 private Endpoint() {
16 port = 0;
17 host = null;
18 }
19
Madan Jampaniab6d3112014-10-02 16:30:14 -070020 public Endpoint(String host, int port) {
21 this.host = host;
22 this.port = port;
23 }
24
25 public String host() {
26 return host;
27 }
28
29 public int port() {
30 return port;
31 }
32
33 @Override
34 public String toString() {
35 return "Endpoint [port=" + port + ", host=" + host + "]";
36 }
37
38 @Override
39 public int hashCode() {
40 final int prime = 31;
41 int result = 1;
42 result = prime * result + ((host == null) ? 0 : host.hashCode());
43 result = prime * result + port;
44 return result;
45 }
46
47 @Override
48 public boolean equals(Object obj) {
49 if (this == obj) {
50 return true;
51 }
52 if (obj == null) {
53 return false;
54 }
55 if (getClass() != obj.getClass()) {
56 return false;
57 }
58 Endpoint other = (Endpoint) obj;
59 if (host == null) {
60 if (other.host != null) {
61 return false;
62 }
63 } else if (!host.equals(other.host)) {
64 return false;
65 }
66 if (port != other.port) {
67 return false;
68 }
69 return true;
70 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070071}