[jdom-interest] Helper methods [eg]

Rosen, Alex arosen at silverstream.com
Wed May 2 22:50:48 PDT 2001


Here's a patch for the bug I mentioned a while back. Without it, this will
fail:

	Element e = new Element("test");
	Element e2 = new Element("test2");
	List list = e.getChildren();
	list.add(0, e2);

--Alex

-------------- next part --------------
Index: PartialList.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/PartialList.java,v
retrieving revision 1.9
diff -u -r1.9 PartialList.java
--- PartialList.java	2001/04/27 18:21:20	1.9
+++ PartialList.java	2001/05/03 04:53:26
@@ -143,6 +143,11 @@
      * Inserts the given element at the beginning of this list.
      */
     public void addFirst(Object o) {
+        if (size() == 0) {
+            add(o);
+            return;
+        }
+
         int index = backingList.indexOf(getFirst());
         super.addFirst(o);
 
@@ -162,6 +167,11 @@
      * function to the <tt>add</tt> method; included only for consistency.)
      */
     public void addLast(Object o) {
+        if (size() == 0) {
+            add(o);
+            return;
+        }
+
         int index = backingList.indexOf(getLast());
         super.addLast(o);
 


More information about the jdom-interest mailing list