Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.store.messaging; |
| 2 | |
| 3 | /** |
| 4 | * Representation of a TCP/UDP communication end point. |
| 5 | */ |
| 6 | public class Endpoint { |
| 7 | |
| 8 | private final int port; |
| 9 | private final String host; |
| 10 | |
| 11 | public Endpoint(String host, int port) { |
| 12 | this.host = host; |
| 13 | this.port = port; |
| 14 | } |
| 15 | |
| 16 | public String host() { |
| 17 | return host; |
| 18 | } |
| 19 | |
| 20 | public int port() { |
| 21 | return port; |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public String toString() { |
| 26 | return "Endpoint [port=" + port + ", host=" + host + "]"; |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public int hashCode() { |
| 31 | final int prime = 31; |
| 32 | int result = 1; |
| 33 | result = prime * result + ((host == null) ? 0 : host.hashCode()); |
| 34 | result = prime * result + port; |
| 35 | return result; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public boolean equals(Object obj) { |
| 40 | if (this == obj) { |
| 41 | return true; |
| 42 | } |
| 43 | if (obj == null) { |
| 44 | return false; |
| 45 | } |
| 46 | if (getClass() != obj.getClass()) { |
| 47 | return false; |
| 48 | } |
| 49 | Endpoint other = (Endpoint) obj; |
| 50 | if (host == null) { |
| 51 | if (other.host != null) { |
| 52 | return false; |
| 53 | } |
| 54 | } else if (!host.equals(other.host)) { |
| 55 | return false; |
| 56 | } |
| 57 | if (port != other.port) { |
| 58 | return false; |
| 59 | } |
| 60 | return true; |
| 61 | } |
| 62 | } |