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 org.apache.commons.collections.MapIterator;
20  
21  /**
22   * Provides basic behaviour for decorating a map iterator with extra functionality.
23   * <p>
24   * All methods are forwarded to the decorated map iterator.
25   *
26   * @since 3.0
27   * @version $Id: AbstractMapIteratorDecorator.java 1429905 2013-01-07 17:15:14Z ggregory $
28   */
29  public class AbstractMapIteratorDecorator<K, V> implements MapIterator<K, V> {
30  
31      /** The iterator being decorated */
32      protected final MapIterator<K, V> 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 AbstractMapIteratorDecorator(final MapIterator<K, V> iterator) {
42          super();
43          if (iterator == null) {
44              throw new IllegalArgumentException("MapIterator 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 MapIterator<K, V> getMapIterator() {
55          return iterator;
56      }
57  
58      //-----------------------------------------------------------------------
59      
60      /** {@inheritDoc} */
61      public boolean hasNext() {
62          return iterator.hasNext();
63      }
64  
65      /** {@inheritDoc} */
66      public K next() {
67          return iterator.next();
68      }
69  
70      /** {@inheritDoc} */
71      public void remove() {
72          iterator.remove();
73      }
74  
75      /** {@inheritDoc} */
76      public K getKey() {
77          return iterator.getKey();
78      }
79  
80      /** {@inheritDoc} */
81      public V getValue() {
82          return iterator.getValue();
83      }
84  
85      /** {@inheritDoc} */
86      public V setValue(final V obj) {
87          return iterator.setValue(obj);
88      }
89  
90  }