1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.apache.commons.httpclient.server;
31
32 /***
33 * @author Oleg Kalnichevski
34 */
35 public class SimpleHost implements Cloneable {
36
37 private String hostname = null;
38
39 private int port = -1;
40
41 public SimpleHost(final String hostname, int port) {
42 super();
43 if (hostname == null) {
44 throw new IllegalArgumentException("Host name may not be null");
45 }
46 if (port < 0) {
47 throw new IllegalArgumentException("Port may not be negative");
48 }
49 this.hostname = hostname;
50 this.port = port;
51 }
52
53 public SimpleHost (final SimpleHost httphost) {
54 super();
55 this.hostname = httphost.hostname;
56 this.port = httphost.port;
57 }
58
59 public Object clone() {
60 return new SimpleHost(this);
61 }
62
63 public String getHostName() {
64 return this.hostname;
65 }
66
67 public int getPort() {
68 return this.port;
69 }
70
71 public String toString() {
72 StringBuffer buffer = new StringBuffer(50);
73 buffer.append(this.hostname);
74 buffer.append(':');
75 buffer.append(this.port);
76 return buffer.toString();
77 }
78
79 public boolean equals(final Object o) {
80
81 if (o instanceof SimpleHost) {
82 if (o == this) {
83 return true;
84 }
85 SimpleHost that = (SimpleHost) o;
86 if (!this.hostname.equalsIgnoreCase(that.hostname)) {
87 return false;
88 }
89 if (this.port != that.port) {
90 return false;
91 }
92 return true;
93 } else {
94 return false;
95 }
96 }
97
98 public int hashCode() {
99 return this.hostname.hashCode() + this.port;
100 }
101
102 }