Fixing 2 bugs and adding a nice to have toArrayList() method

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@733888 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2009-01-12 20:17:48 +00:00
parent 050436d72c
commit 47e6d0482b
2 changed files with 16 additions and 3 deletions

View File

@ -117,7 +117,6 @@ public class LinkedNode<T extends LinkedNode<T>> {
rightTail.next = next; // link list->next rightTail.next = next; // link list->next
next.prev = rightTail; // link list<-next next.prev = rightTail; // link list<-next
next = rightHead; // this->list next = rightHead; // this->list
list.size++;
} }
/** /**

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.kahadb.util; package org.apache.kahadb.util;
import java.util.ArrayList;
/** /**
* Provides a list of LinkedNode objects. * Provides a list of LinkedNode objects.
* *
@ -60,9 +62,8 @@ public class LinkedNodeList<T extends LinkedNode<T>> {
return; return;
} }
if (head == null) { if (head == null) {
reparent(list);
head = list.head; head = list.head;
list.head = null; reparent(list);
} else { } else {
getTail().linkAfter(list); getTail().linkAfter(list);
} }
@ -124,4 +125,17 @@ public class LinkedNodeList<T extends LinkedNode<T>> {
return sb.toString(); return sb.toString();
} }
/**
* Copies the nodes of the LinkedNodeList to an ArrayList.
* @return
*/
public ArrayList<T> toArrayList() {
ArrayList<T> rc = new ArrayList<T>(size);
T cur = head;
while( cur!=null ) {
rc.add(cur);
cur = cur.getNext();
}
return rc;
}
} }