Remove the object cache
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / MutableKeySet.java
1 /*
2  * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.opendaylight.yangtools.triemap;
17
18 import java.util.Iterator;
19 import java.util.Spliterator;
20
21 /**
22  * A mutable view of a TrieMap's key set.
23  *
24  * @author Robert Varga
25  *
26  * @param <K> the type of keys
27  */
28 final class MutableKeySet<K> extends AbstractKeySet<K> {
29     MutableKeySet(final MutableTrieMap<K, ?> map) {
30         super(map);
31     }
32
33     @Override
34     public Iterator<K> iterator() {
35         final AbstractIterator<K, ?> itr = map().iterator();
36         return new Iterator<K>() {
37             @Override
38             public boolean hasNext() {
39                 return itr.hasNext();
40             }
41
42             @Override
43             public K next() {
44                 return itr.next().getKey();
45             }
46
47             @Override
48             public void remove() {
49                 itr.remove();
50             }
51         };
52     }
53
54     @Override
55     public void clear() {
56         map().clear();
57     }
58
59     @Override
60     @SuppressWarnings("checkstyle:parameterName")
61     public boolean remove(final Object o) {
62         return map().remove(o) != null;
63     }
64
65     @Override
66     int spliteratorCharacteristics() {
67         return Spliterator.DISTINCT | Spliterator.CONCURRENT | Spliterator.NONNULL;
68     }
69 }