From d380cf18ca25f5380872f65888a1edcc14b4f6f7 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 2 Apr 2005 21:03:33 +0000 Subject: [PATCH] BasicAttributes.java (equals): Compare to any Attributes and attribute order doesn't matter. 2005-04-02 Mark Wielaard * 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). From-SVN: r97461 --- libjava/ChangeLog | 8 +++++ .../naming/directory/BasicAttributes.java | 32 ++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 3492f48e187..291f2546aba 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2005-04-02 Mark Wielaard + + * 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). + 2005-04-01 Thomas Fitzsimmons PR libgcj/20090, PR libgcj/20526 diff --git a/libjava/javax/naming/directory/BasicAttributes.java b/libjava/javax/naming/directory/BasicAttributes.java index 9a9a80019a4..b20072424bc 100644 --- a/libjava/javax/naming/directory/BasicAttributes.java +++ b/libjava/javax/naming/directory/BasicAttributes.java @@ -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 @@ public class BasicAttributes implements Attributes 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)) - return false; - BasicAttributes b = (BasicAttributes) obj; - if (ignoreCase != b.ignoreCase - || attributes.size () != b.attributes.size ()) + if (! (obj instanceof Attributes)) return false; - // Does order matter? - for (int i = 0; i < attributes.size (); ++i) + Attributes bs = (Attributes) obj; + if (ignoreCase != bs.isCaseIgnored() + || attributes.size () != bs.size ()) + return false; + + 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 @@ public class BasicAttributes implements Attributes // 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 class BasicAttributes implements Attributes 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; } }