KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > udp > UDPServerAddress


1 package org.sapia.ubik.net.udp;
2
3 import org.sapia.ubik.net.ServerAddress;
4
5 import java.net.InetAddress JavaDoc;
6
7
8 /**
9  * Implement a <code>ServerAddress</code> around a
10  * an <code>InetAddress</code> and a port.
11  *
12  * @author Yanick Duchesne
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class UDPServerAddress implements ServerAddress {
20   public static final String JavaDoc TRANSPORT_TYPE = "udp/socket";
21   private String JavaDoc _transportType = TRANSPORT_TYPE;
22   private InetAddress JavaDoc _addr;
23   private int _port;
24   private int _hashCode;
25
26   /**
27    * Constructor for InetServerAddress.
28    *
29    * @param addr the <code>InetAddress</code> of the server
30    * to which this instance corresponds.
31    *
32    * @param port the port of the server
33    * to which this instance corresponds.
34    */

35   public UDPServerAddress(InetAddress JavaDoc addr, int port) {
36     _addr = addr;
37     _port = port;
38     _hashCode = (addr.toString() + port).hashCode();
39   }
40
41   public UDPServerAddress(InetAddress JavaDoc addr, int port, String JavaDoc transportType) {
42     _addr = addr;
43     _port = port;
44     _transportType = transportType;
45     _hashCode = (addr.toString() + port).hashCode();
46   }
47
48   /**
49    * Returns this instance's <code>InetAddress</code>.
50    *
51    * @return an <code>InetAddess</code>.
52    */

53   public InetAddress JavaDoc getInetAddress() {
54     return _addr;
55   }
56
57   /**
58    * Returns this instance's port.
59    *
60    * @return a port.
61    */

62   public int getPort() {
63     return _port;
64   }
65
66   /**
67    * @see Object#equals(java.lang.Object)
68    */

69   public boolean equals(Object JavaDoc other) {
70     try {
71       UDPServerAddress addr = (UDPServerAddress) other;
72
73       return addr._addr.equals(_addr) && (addr._port == _port);
74     } catch (ClassCastException JavaDoc e) {
75       return false;
76     }
77   }
78
79   /**
80    * @see ServerAddress#getTransportType()
81    */

82   public String JavaDoc getTransportType() {
83     return _transportType;
84   }
85
86   /**
87    * @see Object#hashCode()
88    */

89   public int hashCode() {
90     return _hashCode;
91   }
92 }
93
Popular Tags