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 | */ |
| 25 | public class Endpoint { |
| 26 | |
| 27 | private final int port; |
| 28 | private final String host; |
| 29 | |
Madan Jampani | 86ed055 | 2014-10-03 16:45:42 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Used for serialization. |
| 32 | */ |
Madan Jampani | 938aa43 | 2014-10-04 17:37:23 -0700 | [diff] [blame] | 33 | @SuppressWarnings("unused") |
Madan Jampani | 86ed055 | 2014-10-03 16:45:42 -0700 | [diff] [blame] | 34 | private Endpoint() { |
| 35 | port = 0; |
| 36 | host = null; |
| 37 | } |
| 38 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 39 | 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 54 | return MoreObjects.toStringHelper(getClass()) |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 55 | .add("host", host) |
Madan Jampani | 15cd0b8 | 2014-10-28 08:40:23 -0700 | [diff] [blame] | 56 | .add("port", port) |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 57 | .toString(); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int hashCode() { |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 62 | return Objects.hash(host, port); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 63 | } |
| 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 76 | Endpoint that = (Endpoint) obj; |
| 77 | return Objects.equals(this.port, that.port) && |
| 78 | Objects.equals(this.host, that.host); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 79 | } |
Yuta HIGUCHI | 92626c0 | 2014-10-06 15:46:18 -0700 | [diff] [blame] | 80 | } |