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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | package Torello.Java.ReadOnly; import java.util.Comparator; import java.util.NavigableMap; import java.util.Collections; import java.util.Map; import java.util.HashMap; import java.util.TreeMap; import java.util.Hashtable; import java.util.Properties; class JavaHTMLReadOnlyNavigableMap<K, V> implements ReadOnlyNavigableMap<K, V> { private final NavigableMap<K, V> nm; JavaHTMLReadOnlyNavigableMap(NavigableMap<K, V> nm) { this.nm = nm; } public ReadOnlyMap.Entry<K, V> lowerEntry(K key) { return new EntryImpl<>(nm.lowerEntry(key)); } public ReadOnlyMap.Entry<K, V> floorEntry(K key) { return new EntryImpl<>(nm.floorEntry(key)); } public ReadOnlyMap.Entry<K, V> ceilingEntry(K key) { return new EntryImpl<>(nm.ceilingEntry(key)); } public ReadOnlyMap.Entry<K, V> higherEntry(K key) { return new EntryImpl<>(nm.higherEntry(key)); } public ReadOnlyMap.Entry<K, V> firstEntry() { return new EntryImpl<>(nm.firstEntry()); } public ReadOnlyMap.Entry<K, V> lastEntry() { return new EntryImpl<>(nm.lastEntry()); } public K lowerKey(K key) { return nm.lowerKey(key); } public K floorKey(K key) { return nm.floorKey(key); } public K ceilingKey(K key) { return nm.ceilingKey(key); } public K higherKey(K key) { return nm.higherKey(key); } public ReadOnlyNavigableMap<K, V> descendingMap() { return new JavaHTMLReadOnlyNavigableMap<>(nm.descendingMap()); } public ReadOnlyNavigableSet<K> navigableKeySet() { return new JavaHTMLReadOnlyNavigableSet<>(nm.navigableKeySet()); } public ReadOnlyNavigableSet<K> descendingKeySet() { return new JavaHTMLReadOnlyNavigableSet<>(nm.descendingKeySet()); } public ReadOnlyNavigableMap<K, V> subMap( K fromKey, boolean fromInclusive, K toKey, boolean toInclusive ) { return new JavaHTMLReadOnlyNavigableMap<> (nm.subMap(fromKey, fromInclusive, toKey, toInclusive)); } public ReadOnlyNavigableMap<K, V> headMap(K toKey, boolean inclusive) { return new JavaHTMLReadOnlyNavigableMap<>(nm.headMap(toKey, inclusive)); } public ReadOnlyNavigableMap<K, V> tailMap(K fromKey, boolean inclusive) { return new JavaHTMLReadOnlyNavigableMap<>(nm.headMap(fromKey, inclusive)); } public ReadOnlySortedMap<K, V> subMap(K fromKey, K toKey) { return new JavaHTMLReadOnlySortedMap<>(nm.subMap(fromKey, toKey)); } public ReadOnlySortedMap<K, V> headMap(K toKey) { return new JavaHTMLReadOnlySortedMap<>(nm.headMap(toKey)); } public ReadOnlySortedMap<K, V> tailMap(K fromKey) { return new JavaHTMLReadOnlySortedMap<>(nm.tailMap(fromKey)); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Copied from ReadOnlySortedMap // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** public Comparator<? super K> comparator() { return nm.comparator(); } public K firstKey() { return nm.firstKey(); } public K lastKey() { return nm.lastKey(); } public ReadOnlySet<K> keySet() { return new JavaHTMLReadOnlySet<>(nm.keySet()); } public ReadOnlyCollection<V> values() { return new JavaHTMLReadOnlyCollection<>(nm.values()); } public ReadOnlySet<ReadOnlyMap.Entry<K, V>> entrySet() { return ROHelperEntrySet.toReadOnlyEntrySet(nm.entrySet()); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Defined in ReadOnlyMap only // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** public V get(Object key) { return nm.get(key); } public boolean containsValue(Object value) { return nm.containsValue(value); } public boolean containsKey(Object key) { return nm.containsKey(key); } public boolean isEmpty() { return nm.isEmpty(); } public int size() { return nm.size(); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // To Java-Collections Types // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** @SuppressWarnings("unchecked") public Map<K, V> cloneToMap() { if (nm instanceof HashMap) return (Map<K, V>) ((HashMap<K, V>) nm).clone(); if (nm instanceof TreeMap) return (Map<K, V>) ((TreeMap<K, V>) nm).clone(); if (nm instanceof Hashtable) return (Map<K, V>) ((Hashtable<K, V>) nm).clone(); if (nm instanceof Properties) return (Map<K, V>) ((Properties) nm).clone(); return new TreeMap<>(nm); } public Map<K, V> wrapToImmutableMap() { return Collections.unmodifiableMap(nm); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // java.lang.Object // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** public int hashCode() { return nm.hashCode(); } public boolean equals(Object other) { return ROHelperEquals.roMapEq(this, other); } public String toString() { return nm.toString(); } } |