View Javadoc

1   package com.atlassian.httpclient.api.factory;
2   
3   import javax.annotation.Nonnull;
4   
5   /**
6    * Represents a host (host name and port).
7    */
8   public class Host {
9       private final String host;
10      private final int port;
11  
12      public Host(@Nonnull final String host, final int port) {
13          if (host == null || host.trim().length() == 0)
14              throw new IllegalArgumentException("Host must not be null or empty");
15          else if (port <= 0 || port > 65535)
16              throw new IllegalArgumentException("Port must be greater than 0 and less than 65535");
17  
18          this.host = host;
19          this.port = port;
20      }
21  
22      public String getHost() {
23          return host;
24      }
25  
26      public int getPort() {
27          return port;
28      }
29  
30      @Override
31      public String toString() {
32          return "Host{" +
33                  "host='" + host + '\'' +
34                  ", port=" + port +
35                  '}';
36      }
37  
38      @Override
39      public boolean equals(Object o) {
40          if (this == o) {
41              return true;
42          }
43          if (o == null || getClass() != o.getClass()) {
44              return false;
45          }
46  
47          Host host1 = (Host) o;
48  
49          if (port != host1.port) {
50              return false;
51          }
52          if (!host.equals(host1.host)) {
53              return false;
54          }
55  
56          return true;
57      }
58  
59      @Override
60      public int hashCode() {
61          int result = host.hashCode();
62          result = 31 * result + port;
63          return result;
64      }
65  }