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.collections4.iterators;
18  
19  import java.util.Objects;
20  
21  import org.apache.commons.collections4.OrderedMapIterator;
22  
23  /**
24   * Provides basic behavior for decorating an ordered map iterator with extra functionality.
25   * <p>
26   * All methods are forwarded to the decorated map iterator.
27   * </p>
28   *
29   * @param <K> the type of keys
30   * @param <V> the type of mapped values
31   * @since 3.0
32   */
33  public class AbstractOrderedMapIteratorDecorator<K, V> implements OrderedMapIterator<K, V> {
34  
35      /** The iterator being decorated */
36      private final OrderedMapIterator<K, V> iterator;
37  
38      /**
39       * Constructor that decorates the specified iterator.
40       *
41       * @param iterator  the iterator to decorate, must not be null
42       * @throws NullPointerException if the iterator is null
43       */
44      public AbstractOrderedMapIteratorDecorator(final OrderedMapIterator<K, V> iterator) {
45          this.iterator = Objects.requireNonNull(iterator, "iterator");
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public K getKey() {
51          return iterator.getKey();
52      }
53  
54      /**
55       * Gets the iterator being decorated.
56       *
57       * @return the decorated iterator
58       */
59      protected OrderedMapIterator<K, V> getOrderedMapIterator() {
60          return iterator;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public V getValue() {
66          return iterator.getValue();
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public boolean hasNext() {
72          return iterator.hasNext();
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public boolean hasPrevious() {
78          return iterator.hasPrevious();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public K next() {
84          return iterator.next();
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public K previous() {
90          return iterator.previous();
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public void remove() {
96          iterator.remove();
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public V setValue(final V value) {
102         return iterator.setValue(value);
103     }
104 
105 }