BUG-7464: Add dedicated key set classes
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / ImmutableKeySet.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 static org.opendaylight.yangtools.triemap.ImmutableTrieMap.unsupported;
19
20 import com.google.common.collect.Iterators;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.Map.Entry;
24
25 /**
26  * An immutable view of a TrieMap's key set.
27  *
28  * @author Robert Varga
29  *
30  * @param <K> the type of keys
31  */
32 final class ImmutableKeySet<K> extends AbstractKeySet<K> {
33     ImmutableKeySet(final TrieMap<K, ?> map) {
34         super(map);
35     }
36
37     @Override
38     public Iterator<K> iterator() {
39         return Iterators.transform(map().immutableIterator(), Entry::getKey);
40     }
41
42     @Override
43     public void clear() {
44         throw unsupported();
45     }
46
47     @Override
48     public boolean remove(final Object o) {
49         throw unsupported();
50     }
51     @Override
52     public boolean retainAll(final Collection<?> c) {
53         throw unsupported();
54     }
55
56     @Override
57     public boolean removeAll(final Collection<?> c) {
58         throw unsupported();
59     }
60 }