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 *
28 * @param <K> the type of keys
29 * @param <V> the type of mapped values
30 * @since 3.0
31 */
32 public class AbstractMapIteratorDecorator<K, V> implements MapIterator<K, V> {
33
34 /** The iterator being decorated */
35 private final MapIterator<K, V> iterator;
36
37 /**
38 * Constructor that decorates the specified iterator.
39 *
40 * @param iterator the iterator to decorate, must not be null
41 * @throws NullPointerException if the iterator is null
42 */
43 public AbstractMapIteratorDecorator(final MapIterator<K, V> iterator) {
44 this.iterator = Objects.requireNonNull(iterator, "iterator");
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public K getKey() {
50 return iterator.getKey();
51 }
52
53 /**
54 * Gets the iterator being decorated.
55 *
56 * @return the decorated iterator
57 */
58 protected MapIterator<K, V> getMapIterator() {
59 return iterator;
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public V getValue() {
65 return iterator.getValue();
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public boolean hasNext() {
71 return iterator.hasNext();
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public K next() {
77 return iterator.next();
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public void remove() {
83 iterator.remove();
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public V setValue(final V obj) {
89 return iterator.setValue(obj);
90 }
91
92 }