View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.model.types;
17  
18  /**
19   * Encapsulates a host string and a port.
20   *
21   * @author Christian Bauer
22   */
23  public class HostPort {
24  
25      private String host;
26      private int port;
27  
28      public HostPort() {
29      }
30  
31      public HostPort(String host, int port) {
32          this.host = host;
33          this.port = port;
34      }
35  
36      public String getHost() {
37          return host;
38      }
39  
40      public void setHost(String host) {
41          this.host = host;
42      }
43  
44      public int getPort() {
45          return port;
46      }
47  
48      public void setPort(int port) {
49          this.port = port;
50      }
51  
52      @Override
53      public boolean equals(Object o) {
54          if (this == o) return true;
55          if (o == null || getClass() != o.getClass()) return false;
56  
57          HostPort hostPort = (HostPort) o;
58  
59          if (port != hostPort.port) return false;
60          if (!host.equals(hostPort.host)) return false;
61  
62          return true;
63      }
64  
65      @Override
66      public int hashCode() {
67          int result = host.hashCode();
68          result = 31 * result + port;
69          return result;
70      }
71  
72      @Override
73      public String toString() {
74          return host + ":" + port;
75      }
76  }