blob: 50bc58dd3a42d334d674fcbd74bfca5655cebb1a [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 */
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080025public final class Endpoint {
Madan Jampaniab6d3112014-10-02 16:30:14 -070026
27 private final int port;
28 private final String host;
29
Madan Jampaniab6d3112014-10-02 16:30:14 -070030 public Endpoint(String host, int port) {
31 this.host = host;
32 this.port = port;
33 }
34
35 public String host() {
36 return host;
37 }
38
39 public int port() {
40 return port;
41 }
42
43 @Override
44 public String toString() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070045 return MoreObjects.toStringHelper(getClass())
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070046 .add("host", host)
Madan Jampani15cd0b82014-10-28 08:40:23 -070047 .add("port", port)
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070048 .toString();
Madan Jampaniab6d3112014-10-02 16:30:14 -070049 }
50
51 @Override
52 public int hashCode() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070053 return Objects.hash(host, port);
Madan Jampaniab6d3112014-10-02 16:30:14 -070054 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61 if (obj == null) {
62 return false;
63 }
64 if (getClass() != obj.getClass()) {
65 return false;
66 }
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070067 Endpoint that = (Endpoint) obj;
68 return Objects.equals(this.port, that.port) &&
69 Objects.equals(this.host, that.host);
Madan Jampaniab6d3112014-10-02 16:30:14 -070070 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070071}