1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.collections.iterators;
  17. import java.util.Iterator;
  18. /**
  19. * A Proxy {@link Iterator Iterator} which delegates its methods to a proxy instance.
  20. *
  21. * @deprecated Use AbstractIteratorDecorator. Will be removed in v4.0
  22. * @since Commons Collections 1.0
  23. * @version $Revision: 1.10 $ $Date: 2004/02/18 00:59:50 $
  24. *
  25. * @author James Strachan
  26. */
  27. public class ProxyIterator implements Iterator {
  28. /** Holds value of property iterator. */
  29. private Iterator iterator;
  30. // Constructors
  31. //-------------------------------------------------------------------------
  32. /**
  33. * Constructs a new <code>ProxyIterator</code> that will not function
  34. * until {@link #setIterator(Iterator)} is called.
  35. */
  36. public ProxyIterator() {
  37. super();
  38. }
  39. /**
  40. * Constructs a new <code>ProxyIterator</code> that will use the
  41. * given iterator.
  42. *
  43. * @param iterator the underlying iterator
  44. */
  45. public ProxyIterator(Iterator iterator) {
  46. super();
  47. this.iterator = iterator;
  48. }
  49. // Iterator interface
  50. //-------------------------------------------------------------------------
  51. /**
  52. * Returns true if the underlying iterator has more elements.
  53. *
  54. * @return true if the underlying iterator has more elements
  55. */
  56. public boolean hasNext() {
  57. return getIterator().hasNext();
  58. }
  59. /**
  60. * Returns the next element from the underlying iterator.
  61. *
  62. * @return the next element from the underlying iterator
  63. * @throws java.util.NoSuchElementException if the underlying iterator
  64. * raises it because it has no more elements
  65. */
  66. public Object next() {
  67. return getIterator().next();
  68. }
  69. /**
  70. * Removes the last returned element from the collection that spawned
  71. * the underlying iterator.
  72. */
  73. public void remove() {
  74. getIterator().remove();
  75. }
  76. // Properties
  77. //-------------------------------------------------------------------------
  78. /** Getter for property iterator.
  79. * @return Value of property iterator.
  80. */
  81. public Iterator getIterator() {
  82. return iterator;
  83. }
  84. /** Setter for property iterator.
  85. * @param iterator New value of property iterator.
  86. */
  87. public void setIterator(Iterator iterator) {
  88. this.iterator = iterator;
  89. }
  90. }