[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent.
From: |
Meskauskas Audrius |
Subject: |
[cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent. |
Date: |
Sun, 06 Nov 2005 14:24:05 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
This method provides better functionality for the
org.omg.CORBA.Object._is_equivalent.
If the objects are remote, it is still possible to check if they are
equivalent by comparing
the host and object key information.
2005-11-06 Audrius Meskauskas <address@hidden>
* gnu/CORBA/IOR.java (equals, hashCode): New methods.
* gnu/CORBA/SimpleDelegate.java (is_equivalent): Compare IORs when
applicable.
Index: gnu/CORBA/IOR.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/IOR.java,v
retrieving revision 1.9
diff -u -r1.9 IOR.java
--- gnu/CORBA/IOR.java 28 Oct 2005 14:05:21 -0000 1.9
+++ gnu/CORBA/IOR.java 6 Nov 2005 13:12:52 -0000
@@ -59,6 +59,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.zip.Adler32;
/**
* The implementaton of the Interoperable Object Reference (IOR). IOR can be
@@ -715,5 +717,45 @@
else
// The future supported tagged profiles should be added here.
throw new BAD_PARAM("Unsupported profile type " + profile.tag);
+ }
+
+ /**
+ * Checks for equality.
+ */
+ public boolean equals(Object x)
+ {
+ if (x instanceof IOR)
+ {
+ boolean keys;
+ boolean hosts = true;
+
+ IOR other = (IOR) x;
+ if (key != null && other.key != null)
+ keys = Arrays.equals(key, other.key);
+ else
+ keys = key == other.key;
+
+ if (Internet != null && Internet.host != null)
+ if (other.Internet != null && other.Internet.host != null)
+ hosts = other.Internet.host.equals(Internet.host);
+
+ return keys & hosts;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Get the hashcode of this IOR.
+ */
+ public int hashCode()
+ {
+ Adler32 adler = new Adler32();
+ if (key != null)
+ adler.update(key);
+ if (Internet != null && Internet.host != null)
+ adler.update(Internet.host.getBytes());
+
+ return (int) adler.getValue();
}
}
Index: gnu/CORBA/SimpleDelegate.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/SimpleDelegate.java,v
retrieving revision 1.1
diff -u -r1.1 SimpleDelegate.java
--- gnu/CORBA/SimpleDelegate.java 28 Oct 2005 12:04:39 -0000 1.1
+++ gnu/CORBA/SimpleDelegate.java 6 Nov 2005 12:50:40 -0000
@@ -196,13 +196,11 @@
}
/**
- * Returns true if the objects are the same of have
- * the same delegate set. All objects in this implementation
- * have a separate delegate.
+ * Returns true if the objects are the same or have the same delegate set.
All
+ * objects in this implementation have a separate delegate.
*/
public boolean is_equivalent(org.omg.CORBA.Object target,
- org.omg.CORBA.Object other
- )
+ org.omg.CORBA.Object other)
{
if (target == other)
return true;
@@ -210,13 +208,25 @@
{
try
{
- org.omg.CORBA.portable.Delegate a =
- ((ObjectImpl) target)._get_delegate();
- org.omg.CORBA.portable.Delegate b =
- ((ObjectImpl) other)._get_delegate();
+ org.omg.CORBA.portable.Delegate a = ((ObjectImpl)
target)._get_delegate();
+ org.omg.CORBA.portable.Delegate b = ((ObjectImpl)
other)._get_delegate();
if (a == b)
{
return true;
+ }
+ else
+ {
+ // We compere the IOR's in this case.
+ if (a instanceof IorProvider && b instanceof IorProvider)
+ {
+ IOR ia = ((IorProvider) a).getIor();
+ IOR ib = ((IorProvider) b).getIor();
+
+ if (ia != null && ib != null)
+ return (ia.equals(ib));
+ else
+ return ia == ib;
+ }
}
if (a != null && b != null)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent.,
Meskauskas Audrius <=