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
31 package org.apache.commons.httpclient.server;
32
33 /***
34 * @author Oleg Kalnichevski
35 */
36 public class SimpleHost implements Cloneable {
37
38 private String hostname = null;
39
40 private int port = -1;
41
42 public SimpleHost(final String hostname, int port) {
43 super();
44 if (hostname == null) {
45 throw new IllegalArgumentException("Host name may not be null");
46 }
47 if (port < 0) {
48 throw new IllegalArgumentException("Port may not be negative");
49 }
50 this.hostname = hostname;
51 this.port = port;
52 }
53
54 public SimpleHost (final SimpleHost httphost) {
55 super();
56 init(httphost);
57 }
58
59 private void init(final SimpleHost httphost) {
60 this.hostname = httphost.hostname;
61 this.port = httphost.port;
62 }
63
64 public Object clone() throws CloneNotSupportedException {
65 SimpleHost copy = (SimpleHost) super.clone();
66 copy.init(this);
67 return copy;
68 }
69
70 public String getHostName() {
71 return this.hostname;
72 }
73
74 public int getPort() {
75 return this.port;
76 }
77
78 public String toString() {
79 StringBuffer buffer = new StringBuffer(50);
80 buffer.append(this.hostname);
81 buffer.append(':');
82 buffer.append(this.port);
83 return buffer.toString();
84 }
85
86 public boolean equals(final Object o) {
87
88 if (o instanceof SimpleHost) {
89 if (o == this) {
90 return true;
91 }
92 SimpleHost that = (SimpleHost) o;
93 if (!this.hostname.equalsIgnoreCase(that.hostname)) {
94 return false;
95 }
96 if (this.port != that.port) {
97 return false;
98 }
99 return true;
100 } else {
101 return false;
102 }
103 }
104
105 public int hashCode() {
106 return this.hostname.hashCode() + this.port;
107 }
108
109 }