1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleHost.java,v 1.1 2004/11/13 12:21:28 olegk Exp $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 2002-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
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 }