[Patch] javax.naming.directory.BasicAttributes
Michael Koch
konqueror@gmx.de
Sat Apr 2 13:44:00 GMT 2005
Hi list,
I prepared the attached patch to merge
javax.naming.directory.BasicAttributes with classpath.
Ok for trunk and 4.0?
Michael
2005-04-02 Mark Wielaard <mark@klomp.org>
* 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).
-------------- next part --------------
Index: javax/naming/directory/BasicAttributes.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/naming/directory/BasicAttributes.java,v
retrieving revision 1.5
diff -u -r1.5 BasicAttributes.java
--- javax/naming/directory/BasicAttributes.java 6 Nov 2004 23:29:12 -0000 1.5
+++ javax/naming/directory/BasicAttributes.java 2 Apr 2005 13:40:50 -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;
}
}
More information about the Java-patches
mailing list