1 7 8 package java.net; 9 10 21 public class Proxy { 22 23 28 public enum Type { 29 32 DIRECT, 33 36 HTTP, 37 40 SOCKS 41 }; 42 43 private Type type; 44 private SocketAddress sa; 45 46 55 public final static Proxy NO_PROXY = new Proxy (); 56 57 private Proxy() { 59 type = type.DIRECT; 60 sa = null; 61 } 62 63 76 public Proxy(Type type, SocketAddress sa) { 77 if ((type == Type.DIRECT) || !(sa instanceof InetSocketAddress )) 78 throw new IllegalArgumentException ("type " + type + " is not compatible with address " + sa); 79 this.type = type; 80 this.sa = sa; 81 } 82 83 88 public Type type() { 89 return type; 90 } 91 92 99 public SocketAddress address() { 100 return sa; 101 } 102 103 111 public String toString() { 112 if (type() == Type.DIRECT) 113 return "DIRECT"; 114 return type() + " @ " + address(); 115 } 116 117 131 public final boolean equals(Object obj) { 132 if (obj == null || !(obj instanceof Proxy )) 133 return false; 134 Proxy p = (Proxy ) obj; 135 if (p.type() == type()) { 136 if (address() == null) { 137 return (p.address() == null); 138 } else 139 return address().equals(p.address()); 140 } 141 return false; 142 } 143 144 149 public final int hashCode() { 150 if (address() == null) 151 return type().hashCode(); 152 return type().hashCode() + address().hashCode(); 153 } 154 } 155 | Popular Tags |