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