1 24 25 package org.objectweb.tribe.common; 26 27 import java.net.InetAddress ; 28 29 35 public class IpAddress implements Address 36 { 37 38 private InetAddress address; 39 private int port; 40 41 44 public IpAddress(InetAddress address, int port) 45 { 46 this.address = address; 47 this.port = port; 48 } 49 50 55 public InetAddress getAddress() 56 { 57 return address; 58 } 59 60 65 public void setAddress(InetAddress address) 66 { 67 this.address = address; 68 } 69 70 75 public void setPort(int port) 76 { 77 this.port = port; 78 } 79 80 85 public int getPort() 86 { 87 return port; 88 } 89 90 93 public String toString() 94 { 95 return address.toString() + ":" + port; 96 } 97 98 101 public boolean equals(Object obj) 102 { 103 if (obj instanceof IpAddress) 104 { 105 IpAddress ip = (IpAddress) obj; 106 return (this.port == ip.port) 107 && (((this.getAddress() == null) && (ip.getAddress() == null)) || this 108 .getAddress().equals(ip.getAddress())); 109 } 110 return false; 111 } 112 113 116 public int hashCode() 117 { 118 return address.hashCode() + port; 119 } 120 121 124 public int compareTo(Object o) 125 { 126 if (o instanceof IpAddress) 127 return address.toString().compareTo( 128 ((IpAddress) o).getAddress().toString()); 129 else 130 throw new ClassCastException ( 131 "IpAddress can only be compared with another IpAddress"); 132 } 133 134 } | Popular Tags |