01: /* ReverseIterator.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: * www.ddsteps.org
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License version 2.1 as published by the Free Software Foundation.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, visit
18: * http://www.opensource.org/licenses/lgpl-license.php
19: */
20:
21: package org.ddsteps.fixture.ldap.support;
22:
23: import java.util.Iterator;
24: import java.util.LinkedList;
25:
26: /**
27: * A wrapper to reverse the order of a supplied iterator instance. The iteration
28: * will start at the last element of the supplied iterator and proceed
29: * backwards. It is imperative that the wrapped Iterator be finite and
30: * non-blocking, as this wrapper needs to iterate through all entries on
31: * startup.
32: *
33: * @author Mattias Arthursson
34: */
35: public class ReverseIterator implements Iterator {
36:
37: private Iterator myIterator;
38:
39: /**
40: * Default constructor.
41: *
42: * @param iterator
43: * the Iterator to reverse.
44: */
45: public ReverseIterator(Iterator iterator) {
46: LinkedList list = new LinkedList();
47: while (iterator.hasNext()) {
48: list.addFirst(iterator.next());
49: }
50:
51: myIterator = list.iterator();
52: }
53:
54: /*
55: * (non-Javadoc)
56: *
57: * @see java.util.Iterator#hasNext()
58: */
59: public boolean hasNext() {
60: return myIterator.hasNext();
61: }
62:
63: /*
64: * (non-Javadoc)
65: *
66: * @see java.util.Iterator#next()
67: */
68: public Object next() {
69: return myIterator.next();
70: }
71:
72: /**
73: * Not supported for this implementation.
74: *
75: * @throws UnsupportedOperationException
76: */
77: public void remove() {
78: throw new UnsupportedOperationException(
79: "Not supported for this class");
80: }
81:
82: }
|