001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.iterators;
017:
018: import java.util.Iterator;
019:
020: /**
021: * A Proxy {@link Iterator Iterator} which delegates its methods to a proxy instance.
022: *
023: * @deprecated Use AbstractIteratorDecorator. Will be removed in v4.0
024: * @since Commons Collections 1.0
025: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
026: *
027: * @author James Strachan
028: */
029: public class ProxyIterator implements Iterator {
030:
031: /** Holds value of property iterator. */
032: private Iterator iterator;
033:
034: // Constructors
035: //-------------------------------------------------------------------------
036:
037: /**
038: * Constructs a new <code>ProxyIterator</code> that will not function
039: * until {@link #setIterator(Iterator)} is called.
040: */
041: public ProxyIterator() {
042: super ();
043: }
044:
045: /**
046: * Constructs a new <code>ProxyIterator</code> that will use the
047: * given iterator.
048: *
049: * @param iterator the underlying iterator
050: */
051: public ProxyIterator(Iterator iterator) {
052: super ();
053: this .iterator = iterator;
054: }
055:
056: // Iterator interface
057: //-------------------------------------------------------------------------
058:
059: /**
060: * Returns true if the underlying iterator has more elements.
061: *
062: * @return true if the underlying iterator has more elements
063: */
064: public boolean hasNext() {
065: return getIterator().hasNext();
066: }
067:
068: /**
069: * Returns the next element from the underlying iterator.
070: *
071: * @return the next element from the underlying iterator
072: * @throws java.util.NoSuchElementException if the underlying iterator
073: * raises it because it has no more elements
074: */
075: public Object next() {
076: return getIterator().next();
077: }
078:
079: /**
080: * Removes the last returned element from the collection that spawned
081: * the underlying iterator.
082: */
083: public void remove() {
084: getIterator().remove();
085: }
086:
087: // Properties
088: //-------------------------------------------------------------------------
089: /** Getter for property iterator.
090: * @return Value of property iterator.
091: */
092: public Iterator getIterator() {
093: return iterator;
094: }
095:
096: /** Setter for property iterator.
097: * @param iterator New value of property iterator.
098: */
099: public void setIterator(Iterator iterator) {
100: this.iterator = iterator;
101: }
102: }
|