1 30 31 package org.apache.commons.httpclient.server; 32 33 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 } 110 | Popular Tags |