blob: a9b3b461e3b71c597cb6d33575c63edfab8cddd3 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Madan Jampaniab6d3112014-10-02 16:30:14 -070019package org.onlab.netty;
20
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070021import java.util.Objects;
22
23import com.google.common.base.MoreObjects;
24
Madan Jampaniab6d3112014-10-02 16:30:14 -070025/**
26 * Representation of a TCP/UDP communication end point.
27 */
28public class Endpoint {
29
30 private final int port;
31 private final String host;
32
Madan Jampani86ed0552014-10-03 16:45:42 -070033 /**
34 * Used for serialization.
35 */
Madan Jampani938aa432014-10-04 17:37:23 -070036 @SuppressWarnings("unused")
Madan Jampani86ed0552014-10-03 16:45:42 -070037 private Endpoint() {
38 port = 0;
39 host = null;
40 }
41
Madan Jampaniab6d3112014-10-02 16:30:14 -070042 public Endpoint(String host, int port) {
43 this.host = host;
44 this.port = port;
45 }
46
47 public String host() {
48 return host;
49 }
50
51 public int port() {
52 return port;
53 }
54
55 @Override
56 public String toString() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070057 return MoreObjects.toStringHelper(getClass())
58 .add("port", port)
59 .add("host", host)
60 .toString();
Madan Jampaniab6d3112014-10-02 16:30:14 -070061 }
62
63 @Override
64 public int hashCode() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070065 return Objects.hash(host, port);
Madan Jampaniab6d3112014-10-02 16:30:14 -070066 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj == null) {
74 return false;
75 }
76 if (getClass() != obj.getClass()) {
77 return false;
78 }
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070079 Endpoint that = (Endpoint) obj;
80 return Objects.equals(this.port, that.port) &&
81 Objects.equals(this.host, that.host);
Madan Jampaniab6d3112014-10-02 16:30:14 -070082 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070083}