瀏覽代碼

Refactor to use an inner class, as per the standard Java SDK Iterator implementations.

Ben Alex 20 年之前
父節點
當前提交
958a45af69

+ 55 - 1
domain/src/main/java/org/acegisecurity/domain/dao/PaginatedList.java

@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.NoSuchElementException;
 import java.util.Vector;
 
 
@@ -315,7 +316,7 @@ public class PaginatedList implements List {
     }
 
     public Iterator iterator() {
-        return new PaginatedListIterator(this);
+        return new PaginatedListIterator();
     }
 
     /**
@@ -474,4 +475,57 @@ public class PaginatedList implements List {
 
         return list.toArray(arg0);
     }
+
+    //~ Inner Classes ==========================================================
+
+    private class PaginatedListIterator implements Iterator {
+        private Iterator iterator;
+        private int i = 0;
+
+        /**
+         * @see java.util.Iterator#hasNext()
+         */
+        public boolean hasNext() {
+            return i < size();
+        }
+
+        /**
+         * This method follows the rules of Iterator.next() except that it
+         * returns null when requesting an element that it's not in the
+         * current page.
+         *
+         * @see java.util.Iterator#next()
+         */
+        public Object next() {
+            if (i == getFirstElement()) {
+                iterator = getList().iterator();
+            }
+
+            if ((i >= getFirstElement())
+                && (i < (getFirstElement() + getMaxElements()))) {
+                i++;
+
+                return iterator.next();
+            }
+
+            if (hasNext()) {
+                i++;
+
+                return null;
+            } else {
+                throw new NoSuchElementException();
+            }
+        }
+
+        /**
+         * Unsupported operation
+         *
+         * @throws UnsupportedOperationException
+         *
+         * @see java.util.Iterator#remove()
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+    }
 }

+ 0 - 92
domain/src/main/java/org/acegisecurity/domain/dao/PaginatedListIterator.java

@@ -1,92 +0,0 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.sf.acegisecurity.domain.dao;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-
-/**
- * An iterator of the <code>PaginatedList</code>.
- *
- * @author Carlos Sanchez
- * @version $Id$
- */
-public class PaginatedListIterator implements Iterator {
-    //~ Instance fields ========================================================
-
-    private Iterator iterator;
-    private PaginatedList list;
-    private int i = 0;
-
-    //~ Constructors ===========================================================
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param list
-     */
-    public PaginatedListIterator(PaginatedList list) {
-        this.list = list;
-    }
-
-    //~ Methods ================================================================
-
-    /**
-     * @see java.util.Iterator#hasNext()
-     */
-    public boolean hasNext() {
-        return i < list.size();
-    }
-
-    /**
-     * This method follows the rules of Iterator.next() except that it returns
-     * null when requesting an element that it's not in the current page.
-     *
-     * @see java.util.Iterator#next()
-     */
-    public Object next() {
-        if (i == list.getFirstElement()) {
-            iterator = list.getList().iterator();
-        }
-
-        if ((i >= list.getFirstElement())
-            && (i < (list.getFirstElement() + list.getMaxElements()))) {
-            i++;
-
-            return iterator.next();
-        }
-
-        if (hasNext()) {
-            i++;
-
-            return null;
-        } else {
-            throw new NoSuchElementException();
-        }
-    }
-
-    /**
-     * Unsupported operation
-     *
-     * @throws UnsupportedOperationException
-     *
-     * @see java.util.Iterator#remove()
-     */
-    public void remove() {
-        throw new UnsupportedOperationException();
-    }
-}