Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 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 Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 19 | package org.onlab.netty; |
| 20 | |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
| 23 | import com.google.common.base.MoreObjects; |
| 24 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Representation of a TCP/UDP communication end point. |
| 27 | */ |
| 28 | public class Endpoint { |
| 29 | |
| 30 | private final int port; |
| 31 | private final String host; |
| 32 | |
Madan Jampani | 86ed055 | 2014-10-03 16:45:42 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Used for serialization. |
| 35 | */ |
Madan Jampani | 938aa43 | 2014-10-04 17:37:23 -0700 | [diff] [blame] | 36 | @SuppressWarnings("unused") |
Madan Jampani | 86ed055 | 2014-10-03 16:45:42 -0700 | [diff] [blame] | 37 | private Endpoint() { |
| 38 | port = 0; |
| 39 | host = null; |
| 40 | } |
| 41 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 42 | 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 57 | return MoreObjects.toStringHelper(getClass()) |
| 58 | .add("port", port) |
| 59 | .add("host", host) |
| 60 | .toString(); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
Yuta HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 65 | return Objects.hash(host, port); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 66 | } |
| 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 HIGUCHI | 97b8167 | 2014-10-06 23:07:56 -0700 | [diff] [blame] | 79 | Endpoint that = (Endpoint) obj; |
| 80 | return Objects.equals(this.port, that.port) && |
| 81 | Objects.equals(this.host, that.host); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 82 | } |
Yuta HIGUCHI | 92626c0 | 2014-10-06 15:46:18 -0700 | [diff] [blame] | 83 | } |