| Home >> All |
Source code: Freenet/Address.java
1 package Freenet; 2 3 import java.lang.reflect.*; 4 import java.io.Serializable; 5 6 public class Address implements Serializable 7 { 8 public String protocol; 9 public ProtocolAddress address; 10 11 public Address(String protocol, ProtocolAddress addr) 12 { 13 this.protocol = protocol; 14 this.address = addr; 15 } 16 17 public Address(String str) 18 { 19 try 20 { 21 int i=str.indexOf('/'); 22 if(i==-1) throw new IllegalArgumentException(); 23 protocol=str.substring(0,i); 24 Class c=Class.forName("Freenet."+protocol+"Address"); 25 Class[] carr={java.lang.String.class}; 26 Constructor con=c.getConstructor(carr); 27 Object[] oarr={str.substring(i+1)}; 28 address=(ProtocolAddress)con.newInstance(oarr); 29 } 30 catch(Exception e) { throw new IllegalArgumentException(e.toString()); } 31 } 32 33 public String toString() 34 { 35 return protocol+"/"+address; 36 } 37 38 public int hashCode() 39 { 40 return toString().hashCode(); 41 } 42 43 public ListeningAddress listenPart() { 44 return new ListeningAddress(protocol,address.listenPart()); 45 } 46 47 public boolean equals(Object o) 48 { 49 return ((o instanceof Address) && 50 (((Address) o).protocol.equals(protocol)) && 51 (((Address) o).address.equals(address))); 52 53 } 54 55 public boolean equalsHost(Object o) 56 { 57 return ((o != null) && 58 (o instanceof Address) && 59 ((Address) o).protocol.equals(protocol) && 60 ((Address) o).address.equalsHost(address)); 61 } 62 }