Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 16 | package org.onlab.netty; |
| 17 | |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Representation of a TCP/UDP communication end point. |
| 24 | */ |
Yuta HIGUCHI | 91768e3 | 2014-11-22 05:06:35 -0800 | [diff] [blame^] | 25 | public final class Endpoint { |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 26 | |
| 27 | private final int port; |
| 28 | private final String host; |
| 29 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 30 | 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 45 | return MoreObjects.toStringHelper(getClass()) |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 46 | .add("host", host) |
Madan Jampani | 15cd0b8 | 2014-10-28 08:40:23 -0700 | [diff] [blame] | 47 | .add("port", port) |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 48 | .toString(); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public int hashCode() { |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 53 | return Objects.hash(host, port); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 54 | } |
| 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 67 | Endpoint that = (Endpoint) obj; |
| 68 | return Objects.equals(this.port, that.port) && |
| 69 | Objects.equals(this.host, that.host); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 70 | } |
Yuta HIGUCHI | 92626c0 | 2014-10-06 15:46:18 -0700 | [diff] [blame] | 71 | } |