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.MapIterator;
22
23 /**
24 * Provides basic behavior for decorating a 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 AbstractMapIteratorDecorator<K, V> implements MapIterator<K, V> {
34
35 /** The iterator being decorated */
36 private final MapIterator<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 AbstractMapIteratorDecorator(final MapIterator<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 MapIterator<K, V> getMapIterator() {
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 K next() {
78 return iterator.next();
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 public void remove() {
84 iterator.remove();
85 }
86
87 /** {@inheritDoc} */
88 @Override
89 public V setValue(final V value) {
90 return iterator.setValue(value);
91 }
92
93 }