[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Fix javax.naming.directory.BasicAttributes
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: Fix javax.naming.directory.BasicAttributes |
Date: |
Thu, 20 Jan 2005 11:16:41 +0100 |
Hi,
BasicAttributes equals() should compare equal to any Attribute, not just
BasicAttributes. And the BasicAttributesEnumeration had a little thinko
in the use of the 'where' variable. hasMore() and nextElement() didn't
agree on the offset into the array of attributes.
2005-01-20 Mark Wielaard <address@hidden>
* javax/naming/directory/BasicAttributes.java (equals): Compare to any
Attributes and attribute order doesn't matter.
(BasicAttributesEnumeration.where): Initialize to zero.
(BasicAttributesEnumeration.nextElement): Update and compare where
appropriately (zero based).
This makes us pass all gump ldap-common tests.
Committed,
Mark
Index: javax/naming/directory/BasicAttributes.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/naming/directory/BasicAttributes.java,v
retrieving revision 1.4
diff -u -r1.4 BasicAttributes.java
--- javax/naming/directory/BasicAttributes.java 6 Nov 2004 23:31:50 -0000
1.4
+++ javax/naming/directory/BasicAttributes.java 20 Jan 2005 10:10:20 -0000
@@ -1,5 +1,5 @@
/* BasicAttributes.java --
- Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -83,19 +83,27 @@
return ba;
}
+ /**
+ * Returns true if and only if the given Object is an instance of
+ * Attributes, the given attributes both do or don't ignore case for
+ * IDs and the collection of attributes is the same.
+ */
public boolean equals (Object obj)
{
- if (! (obj instanceof BasicAttributes))
+ if (! (obj instanceof Attributes))
return false;
- BasicAttributes b = (BasicAttributes) obj;
- if (ignoreCase != b.ignoreCase
- || attributes.size () != b.attributes.size ())
+
+ Attributes bs = (Attributes) obj;
+ if (ignoreCase != bs.isCaseIgnored()
+ || attributes.size () != bs.size ())
return false;
- // Does order matter?
- for (int i = 0; i < attributes.size (); ++i)
+ NamingEnumeration bas = bs.getAll();
+ while (bas.hasMoreElements())
{
- if (! attributes.get (i).equals (b.attributes.get (i)))
+ Attribute a = (Attribute) bas.nextElement();
+ Attribute b = get(a.getID ());
+ if (! a.equals(b))
return false;
}
@@ -191,7 +199,7 @@
// Used when enumerating.
private class BasicAttributesEnumeration implements NamingEnumeration
{
- int where = -1;
+ int where = 0;
boolean id;
public BasicAttributesEnumeration (boolean id)
@@ -220,10 +228,10 @@
public Object nextElement () throws NoSuchElementException
{
- if (where + 1 >= attributes.size ())
+ if (where >= attributes.size ())
throw new NoSuchElementException ("no more elements");
- ++where;
Attribute at = (Attribute) attributes.get (where);
+ ++where;
return id ? (Object) at.getID () : (Object) at;
}
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Fix javax.naming.directory.BasicAttributes,
Mark Wielaard <=