[jboss-svn-commits] JBL Code SVN: r6997 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 20 22:56:21 EDT 2006
Author: mark.proctor at jboss.com
Date: 2006-10-20 22:56:19 -0400 (Fri, 20 Oct 2006)
New Revision: 6997
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java
Log:
-LinkedList should impl the fast org.drools.util.Iterator
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java 2006-10-21 02:29:54 UTC (rev 6996)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LinkedList.java 2006-10-21 02:56:19 UTC (rev 6997)
@@ -1,8 +1,6 @@
package org.drools.util;
import java.io.Serializable;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
/*
* Copyright 2005 JBoss Inc
@@ -53,11 +51,13 @@
private int size;
+ private LinkedListIterator iterator;
+
/**
* Construct an empty <code>LinkedList</code>
*/
public LinkedList() {
-
+ this.iterator = new LinkedListIterator();
}
/**
@@ -246,38 +246,31 @@
return true;
}
+ public Iterator iterator() {
+ this.iterator.reset( this );
+ return this.iterator();
+ }
+
/**
* Returns a list iterator
* @return
*/
- public Iterator iterator() {
- return new Iterator() {
- private LinkedListNode currentNode = null;
- private LinkedListNode nextNode = getFirst();
-
- public boolean hasNext() {
- return (this.nextNode != null);
+ public class LinkedListIterator {
+ private LinkedList list;
+ private LinkedListNode current;
+
+ public void reset( LinkedList list) {
+ this.list = list;
+ }
+
+ public LinkedListNode next() {
+ if ( this.current == null ) {
+ this.current = this.list.firstNode;
}
-
- public Object next() {
- this.currentNode = this.nextNode;
- if ( this.currentNode != null ) {
- this.nextNode = this.currentNode.getNext();
- } else {
- throw new NoSuchElementException( "No more elements to return" );
- }
- return this.currentNode;
- }
-
- public void remove() {
- if ( this.currentNode != null ) {
- LinkedList.this.remove( this.currentNode );
- this.currentNode = null;
- } else {
- throw new IllegalStateException( "No item to remove. Call next() before calling remove()." );
- }
- }
- };
+ LinkedListNode node = this.current;
+ current = current.getNext();
+ return node;
+ }
}
}
More information about the jboss-svn-commits
mailing list