001: /*
002: * $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 $
003: * $Revision: 510582 $
004: * $Date: 2007-02-22 17:42:43 +0100 (Thu, 22 Feb 2007) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.commons.httpclient.server;
032:
033: /**
034: * @author Oleg Kalnichevski
035: */
036: public class SimpleHost implements Cloneable {
037:
038: private String hostname = null;
039:
040: private int port = -1;
041:
042: public SimpleHost(final String hostname, int port) {
043: super ();
044: if (hostname == null) {
045: throw new IllegalArgumentException(
046: "Host name may not be null");
047: }
048: if (port < 0) {
049: throw new IllegalArgumentException(
050: "Port may not be negative");
051: }
052: this .hostname = hostname;
053: this .port = port;
054: }
055:
056: public SimpleHost(final SimpleHost httphost) {
057: super ();
058: init(httphost);
059: }
060:
061: private void init(final SimpleHost httphost) {
062: this .hostname = httphost.hostname;
063: this .port = httphost.port;
064: }
065:
066: public Object clone() throws CloneNotSupportedException {
067: SimpleHost copy = (SimpleHost) super .clone();
068: copy.init(this );
069: return copy;
070: }
071:
072: public String getHostName() {
073: return this .hostname;
074: }
075:
076: public int getPort() {
077: return this .port;
078: }
079:
080: public String toString() {
081: StringBuffer buffer = new StringBuffer(50);
082: buffer.append(this .hostname);
083: buffer.append(':');
084: buffer.append(this .port);
085: return buffer.toString();
086: }
087:
088: public boolean equals(final Object o) {
089:
090: if (o instanceof SimpleHost) {
091: if (o == this ) {
092: return true;
093: }
094: SimpleHost that = (SimpleHost) o;
095: if (!this .hostname.equalsIgnoreCase(that.hostname)) {
096: return false;
097: }
098: if (this .port != that.port) {
099: return false;
100: }
101: return true;
102: } else {
103: return false;
104: }
105: }
106:
107: public int hashCode() {
108: return this.hostname.hashCode() + this.port;
109: }
110:
111: }
|