From 958a45af6940fb1a3ced0c0974c813c4385527ce Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Wed, 20 Apr 2005 12:05:54 +0000 Subject: [PATCH] Refactor to use an inner class, as per the standard Java SDK Iterator implementations. --- .../domain/dao/PaginatedList.java | 56 ++++++++++- .../domain/dao/PaginatedListIterator.java | 92 ------------------- 2 files changed, 55 insertions(+), 93 deletions(-) delete mode 100644 domain/src/main/java/org/acegisecurity/domain/dao/PaginatedListIterator.java diff --git a/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedList.java b/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedList.java index 7cf753b775..df78d12b47 100644 --- a/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedList.java +++ b/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(); + } + } } diff --git a/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedListIterator.java b/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedListIterator.java deleted file mode 100644 index 4510599f1b..0000000000 --- a/domain/src/main/java/org/acegisecurity/domain/dao/PaginatedListIterator.java +++ /dev/null @@ -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 PaginatedList. - * - * @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(); - } -}