summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-03-15 17:31:40 +0000
committerMark Spruiell <mes@zeroc.com>2002-03-15 17:31:40 +0000
commitcc2d33bed4baaaef7b88ac2073902c8ba56a2af3 (patch)
tree661bea1cf5921d6fd1ed99e58556d537b736ac54 /java/src
parentFixed up the slice2docbook for the SslExtension and SslSystem related (diff)
downloadice-cc2d33bed4baaaef7b88ac2073902c8ba56a2af3.tar.bz2
ice-cc2d33bed4baaaef7b88ac2073902c8ba56a2af3.tar.xz
ice-cc2d33bed4baaaef7b88ac2073902c8ba56a2af3.zip
adding hashCode
Diffstat (limited to 'java/src')
-rw-r--r--java/src/IceInternal/TcpEndpoint.java19
-rw-r--r--java/src/IceInternal/UdpEndpoint.java19
-rw-r--r--java/src/IceInternal/UnknownEndpoint.java18
3 files changed, 56 insertions, 0 deletions
diff --git a/java/src/IceInternal/TcpEndpoint.java b/java/src/IceInternal/TcpEndpoint.java
index fd0fd5b6241..ac4ac6a2a5d 100644
--- a/java/src/IceInternal/TcpEndpoint.java
+++ b/java/src/IceInternal/TcpEndpoint.java
@@ -19,6 +19,7 @@ public final class TcpEndpoint extends Endpoint
_host = ho;
_port = po;
_timeout = ti;
+ calcHashValue();
}
public
@@ -114,6 +115,8 @@ public final class TcpEndpoint extends Endpoint
{
_host = _instance.defaultHost();
}
+
+ calcHashValue();
}
public
@@ -125,6 +128,7 @@ public final class TcpEndpoint extends Endpoint
_port = s.readInt();
_timeout = s.readInt();
s.endReadEncaps();
+ calcHashValue();
}
//
@@ -294,6 +298,12 @@ public final class TcpEndpoint extends Endpoint
return tcpAcceptor.equivalent(_host, _port);
}
+ public int
+ hashCode()
+ {
+ return _hashCode;
+ }
+
//
// Compare endpoints for sorting purposes
//
@@ -368,8 +378,17 @@ public final class TcpEndpoint extends Endpoint
return 0;
}
+ private void
+ calcHashValue()
+ {
+ _hashCode = _host.hashCode();
+ _hashCode = 5 * _hashCode + _port;
+ _hashCode = 5 * _hashCode + _timeout;
+ }
+
private Instance _instance;
private String _host;
private int _port;
private int _timeout;
+ private int _hashCode;
}
diff --git a/java/src/IceInternal/UdpEndpoint.java b/java/src/IceInternal/UdpEndpoint.java
index 5b0bd64bcba..c68ea00de06 100644
--- a/java/src/IceInternal/UdpEndpoint.java
+++ b/java/src/IceInternal/UdpEndpoint.java
@@ -19,6 +19,7 @@ public final class UdpEndpoint extends Endpoint
_host = ho;
_port = po;
_connect = false;
+ calcHashValue();
}
public
@@ -106,6 +107,8 @@ public final class UdpEndpoint extends Endpoint
{
_host = instance.defaultHost();
}
+
+ calcHashValue();
}
public
@@ -119,6 +122,7 @@ public final class UdpEndpoint extends Endpoint
//_connect = s.readBool();
_connect = false;
s.endReadEncaps();
+ calcHashValue();
}
//
@@ -281,6 +285,12 @@ public final class UdpEndpoint extends Endpoint
return false;
}
+ public int
+ hashCode()
+ {
+ return _hashCode;
+ }
+
//
// Compare endpoints for sorting purposes
//
@@ -355,8 +365,17 @@ public final class UdpEndpoint extends Endpoint
return 0;
}
+ private void
+ calcHashValue()
+ {
+ _hashCode = _host.hashCode();
+ _hashCode = 5 * _hashCode + _port;
+ _hashCode = 5 * _hashCode + (_connect ? 1 : 0);
+ }
+
private Instance _instance;
private String _host;
private int _port;
private boolean _connect;
+ private int _hashCode;
}
diff --git a/java/src/IceInternal/UnknownEndpoint.java b/java/src/IceInternal/UnknownEndpoint.java
index 5a432316d78..372cb9ed533 100644
--- a/java/src/IceInternal/UnknownEndpoint.java
+++ b/java/src/IceInternal/UnknownEndpoint.java
@@ -21,6 +21,7 @@ public final class UnknownEndpoint extends Endpoint
int sz = s.getReadEncapsSize();
_rawBytes = s.readBlob(sz);
s.endReadEncaps();
+ calcHashValue();
}
//
@@ -164,6 +165,12 @@ public final class UnknownEndpoint extends Endpoint
{
return false;
}
+
+ public int
+ hashCode()
+ {
+ return _hashCode;
+ }
//
// Compare endpoints for sorting purposes
@@ -225,7 +232,18 @@ public final class UnknownEndpoint extends Endpoint
return 0;
}
+ private void
+ calcHashValue()
+ {
+ _hashCode = _type;
+ for (int i = 0; i < _rawBytes.length; i++)
+ {
+ _hashCode = 5 * _hashCode + _rawBytes[i];
+ }
+ }
+
private Instance _instance;
private short _type;
private byte[] _rawBytes;
+ private int _hashCode;
}