1. /*
  2. * Copyright 2003-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. * Provides basic behaviour for decorating an iterator with extra functionality.
  20. * <p>
  21. * All methods are forwarded to the decorated iterator.
  22. *
  23. * @since Commons Collections 3.0
  24. * @version $Revision: 1.4 $ $Date: 2004/02/18 00:59:50 $
  25. *
  26. * @author James Strachan
  27. * @author Stephen Colebourne
  28. */
  29. public class AbstractIteratorDecorator implements Iterator {
  30. /** The iterator being decorated */
  31. protected final Iterator iterator;
  32. //-----------------------------------------------------------------------
  33. /**
  34. * Constructor that decorates the specified iterator.
  35. *
  36. * @param iterator the iterator to decorate, must not be null
  37. * @throws IllegalArgumentException if the collection is null
  38. */
  39. public AbstractIteratorDecorator(Iterator iterator) {
  40. super();
  41. if (iterator == null) {
  42. throw new IllegalArgumentException("Iterator must not be null");
  43. }
  44. this.iterator = iterator;
  45. }
  46. /**
  47. * Gets the iterator being decorated.
  48. *
  49. * @return the decorated iterator
  50. */
  51. protected Iterator getIterator() {
  52. return iterator;
  53. }
  54. //-----------------------------------------------------------------------
  55. public boolean hasNext() {
  56. return iterator.hasNext();
  57. }
  58. public Object next() {
  59. return iterator.next();
  60. }
  61. public void remove() {
  62. iterator.remove();
  63. }
  64. }