blob: ca24e4fb6f2db1f40f364d3ebf5447208fe26ed2 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
Madan Jampaniab6d3112014-10-02 16:30:14 -070016package org.onlab.netty;
17
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070018import java.util.Objects;
19
20import com.google.common.base.MoreObjects;
21
Madan Jampaniab6d3112014-10-02 16:30:14 -070022/**
23 * Representation of a TCP/UDP communication end point.
24 */
25public class Endpoint {
26
27 private final int port;
28 private final String host;
29
Madan Jampani86ed0552014-10-03 16:45:42 -070030 /**
31 * Used for serialization.
32 */
Madan Jampani938aa432014-10-04 17:37:23 -070033 @SuppressWarnings("unused")
Madan Jampani86ed0552014-10-03 16:45:42 -070034 private Endpoint() {
35 port = 0;
36 host = null;
37 }
38
Madan Jampaniab6d3112014-10-02 16:30:14 -070039 public Endpoint(String host, int port) {
40 this.host = host;
41 this.port = port;
42 }
43
44 public String host() {
45 return host;
46 }
47
48 public int port() {
49 return port;
50 }
51
52 @Override
53 public String toString() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070054 return MoreObjects.toStringHelper(getClass())
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070055 .add("host", host)
Madan Jampani15cd0b82014-10-28 08:40:23 -070056 .add("port", port)
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070057 .toString();
Madan Jampaniab6d3112014-10-02 16:30:14 -070058 }
59
60 @Override
61 public int hashCode() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070062 return Objects.hash(host, port);
Madan Jampaniab6d3112014-10-02 16:30:14 -070063 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj == null) {
71 return false;
72 }
73 if (getClass() != obj.getClass()) {
74 return false;
75 }
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070076 Endpoint that = (Endpoint) obj;
77 return Objects.equals(this.port, that.port) &&
78 Objects.equals(this.host, that.host);
Madan Jampaniab6d3112014-10-02 16:30:14 -070079 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070080}