View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections.iterators;
18  
19  import java.util.ListIterator;
20  
21  /**
22   * Provides basic behaviour for decorating a list iterator with extra functionality.
23   * <p>
24   * All methods are forwarded to the decorated list iterator.
25   *
26   * @since 3.0
27   * @version $Id: AbstractListIteratorDecorator.java 1429905 2013-01-07 17:15:14Z ggregory $
28   */
29  public class AbstractListIteratorDecorator<E> implements ListIterator<E> {
30  
31      /** The iterator being decorated */
32      protected final ListIterator<E> iterator;
33  
34      //-----------------------------------------------------------------------
35      /**
36       * Constructor that decorates the specified iterator.
37       *
38       * @param iterator  the iterator to decorate, must not be null
39       * @throws IllegalArgumentException if the collection is null
40       */
41      public AbstractListIteratorDecorator(final ListIterator<E> iterator) {
42          super();
43          if (iterator == null) {
44              throw new IllegalArgumentException("ListIterator must not be null");
45          }
46          this.iterator = iterator;
47      }
48  
49      /**
50       * Gets the iterator being decorated.
51       * 
52       * @return the decorated iterator
53       */
54      protected ListIterator<E> getListIterator() {
55          return iterator;
56      }
57  
58      //-----------------------------------------------------------------------
59      
60      /** {@inheritDoc} */
61      public boolean hasNext() {
62          return iterator.hasNext();
63      }
64  
65      /** {@inheritDoc} */
66      public E next() {
67          return iterator.next();
68      }
69  
70      /** {@inheritDoc} */
71      public int nextIndex() {
72          return iterator.nextIndex();
73      }
74  
75      /** {@inheritDoc} */
76      public boolean hasPrevious() {
77          return iterator.hasPrevious();
78      }
79  
80      /** {@inheritDoc} */
81      public E previous() {
82          return iterator.previous();
83      }
84  
85      /** {@inheritDoc} */
86      public int previousIndex() {
87          return iterator.previousIndex();
88      }
89  
90      /** {@inheritDoc} */
91      public void remove() {
92          iterator.remove();
93      }
94  
95      /** {@inheritDoc} */
96      public void set(final E obj) {
97          iterator.set(obj);
98      }
99  
100     /** {@inheritDoc} */
101     public void add(final E obj) {
102         iterator.add(obj);
103     }
104     
105 }