Commit d380cf18 by Mark Wielaard Committed by Michael Koch

BasicAttributes.java (equals): Compare to any Attributes and attribute order doesn't matter.

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).

From-SVN: r97461
parent 43849cfa
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).
2005-04-01 Thomas Fitzsimmons <fitzsim@redhat.com> 2005-04-01 Thomas Fitzsimmons <fitzsim@redhat.com>
PR libgcj/20090, PR libgcj/20526 PR libgcj/20090, PR libgcj/20526
......
/* BasicAttributes.java -- /* 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. This file is part of GNU Classpath.
...@@ -83,19 +83,27 @@ public class BasicAttributes implements Attributes ...@@ -83,19 +83,27 @@ public class BasicAttributes implements Attributes
return ba; 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) public boolean equals (Object obj)
{ {
if (! (obj instanceof BasicAttributes)) if (! (obj instanceof Attributes))
return false; return false;
BasicAttributes b = (BasicAttributes) obj;
if (ignoreCase != b.ignoreCase Attributes bs = (Attributes) obj;
|| attributes.size () != b.attributes.size ()) if (ignoreCase != bs.isCaseIgnored()
|| attributes.size () != bs.size ())
return false; return false;
// Does order matter? NamingEnumeration bas = bs.getAll();
for (int i = 0; i < attributes.size (); ++i) 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; return false;
} }
...@@ -191,7 +199,7 @@ public class BasicAttributes implements Attributes ...@@ -191,7 +199,7 @@ public class BasicAttributes implements Attributes
// Used when enumerating. // Used when enumerating.
private class BasicAttributesEnumeration implements NamingEnumeration private class BasicAttributesEnumeration implements NamingEnumeration
{ {
int where = -1; int where = 0;
boolean id; boolean id;
public BasicAttributesEnumeration (boolean id) public BasicAttributesEnumeration (boolean id)
...@@ -220,10 +228,10 @@ public class BasicAttributes implements Attributes ...@@ -220,10 +228,10 @@ public class BasicAttributes implements Attributes
public Object nextElement () throws NoSuchElementException public Object nextElement () throws NoSuchElementException
{ {
if (where + 1 >= attributes.size ()) if (where >= attributes.size ())
throw new NoSuchElementException ("no more elements"); throw new NoSuchElementException ("no more elements");
++where;
Attribute at = (Attribute) attributes.get (where); Attribute at = (Attribute) attributes.get (where);
++where;
return id ? (Object) at.getID () : (Object) at; return id ? (Object) at.getID () : (Object) at;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment