|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| package edu.rice.cs.plt.collect; |
|
36 |
| |
|
37 |
| import java.util.*; |
|
38 |
| import java.io.Serializable; |
|
39 |
| import edu.rice.cs.plt.lambda.Lambda; |
|
40 |
| import edu.rice.cs.plt.iter.ImmutableIterator; |
|
41 |
| import edu.rice.cs.plt.iter.MappedIterator; |
|
42 |
| import edu.rice.cs.plt.object.Composite; |
|
43 |
| import edu.rice.cs.plt.object.ObjectUtil; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public class ImmutableMap<K, V> implements LambdaMap<K, V>, Composite, Serializable { |
|
52 |
| |
|
53 |
| |
|
54 |
| protected Map<? extends K, ? extends V> _delegate; |
|
55 |
| |
|
56 |
0
| public ImmutableMap(Map<? extends K, ? extends V> map) { _delegate = map; }
|
|
57 |
| |
|
58 |
0
| public int compositeHeight() { return ObjectUtil.compositeHeight(_delegate) + 1; }
|
|
59 |
0
| public int compositeSize() { return ObjectUtil.compositeSize(_delegate) + 1; }
|
|
60 |
| |
|
61 |
0
| public int size() { return _delegate.size(); }
|
|
62 |
0
| public boolean isEmpty() { return _delegate.isEmpty(); }
|
|
63 |
| |
|
64 |
0
| public V get(Object key) { return _delegate.get(key); }
|
|
65 |
0
| public V value(K key) { return _delegate.get(key); }
|
|
66 |
| |
|
67 |
0
| public boolean containsKey(Object o) { return _delegate.containsKey(o); }
|
|
68 |
0
| public boolean containsValue(Object o) { return _delegate.containsValue(o); }
|
|
69 |
| |
|
70 |
0
| public PredicateSet<K> keySet() { return new ImmutableSet<K>(_delegate.keySet()); }
|
|
71 |
0
| public Collection<V> values() { return Collections.unmodifiableCollection(_delegate.values()); }
|
|
72 |
0
| public Set<Entry<K, V>> entrySet() { return new EntrySet(); }
|
|
73 |
| |
|
74 |
0
| public V put(K key, V value) { throw new UnsupportedOperationException(); }
|
|
75 |
0
| public void putAll(Map<? extends K, ? extends V> t) { throw new UnsupportedOperationException(); }
|
|
76 |
0
| public V remove(Object key) { throw new UnsupportedOperationException(); }
|
|
77 |
0
| public void clear() { throw new UnsupportedOperationException(); }
|
|
78 |
| |
|
79 |
0
| public String toString() { return _delegate.toString(); }
|
|
80 |
0
| public boolean equals(Object o) { return _delegate.equals(o); }
|
|
81 |
0
| public int hashCode() { return _delegate.hashCode(); }
|
|
82 |
| |
|
83 |
| |
|
84 |
0
| public static <K, V> ImmutableMap<K, V> make(Map<? extends K, ? extends V> map) {
|
|
85 |
0
| return new ImmutableMap<K, V>(map);
|
|
86 |
| } |
|
87 |
| |
|
88 |
| private final class EntrySet extends AbstractPredicateSet<Entry<K, V>> implements Serializable { |
|
89 |
0
| @Override public boolean isEmpty() { return _delegate.isEmpty(); }
|
|
90 |
0
| @Override public int size() { return _delegate.size(); }
|
|
91 |
0
| @Override public int size(int bound) { int s = _delegate.size(); return s < bound ? s : bound; }
|
|
92 |
0
| public boolean isInfinite() { return false; }
|
|
93 |
0
| public boolean hasFixedSize() { return false; }
|
|
94 |
0
| public boolean isStatic() { return false; }
|
|
95 |
| |
|
96 |
0
| public boolean contains(Object o) { return _delegate.entrySet().contains(o); }
|
|
97 |
| |
|
98 |
0
| public Iterator<Entry<K, V>> iterator() {
|
|
99 |
0
| Lambda<Entry<? extends K, ? extends V>, Entry<K, V>> factory = ImmutableMapEntry.factory();
|
|
100 |
0
| return ImmutableIterator.make(MappedIterator.make(_delegate.entrySet().iterator(), factory));
|
|
101 |
| } |
|
102 |
| |
|
103 |
0
| @Override public boolean add(Entry<K, V> o) { throw new UnsupportedOperationException(); }
|
|
104 |
0
| @Override public boolean addAll(Collection<? extends Entry<K, V>> c) { throw new UnsupportedOperationException(); }
|
|
105 |
0
| @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
|
106 |
0
| @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
107 |
0
| @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
108 |
0
| @Override public void clear() { throw new UnsupportedOperationException(); }
|
|
109 |
| } |
|
110 |
| |
|
111 |
| } |