1 16 package org.apache.commons.collections.bidimap; 17 18 import java.util.Collection ; 19 import java.util.Map ; 20 import java.util.Set ; 21 import java.util.SortedMap ; 22 23 import org.apache.commons.collections.BidiMap; 24 import org.apache.commons.collections.MapIterator; 25 import org.apache.commons.collections.OrderedBidiMap; 26 import org.apache.commons.collections.OrderedMapIterator; 27 import org.apache.commons.collections.SortedBidiMap; 28 import org.apache.commons.collections.Unmodifiable; 29 import org.apache.commons.collections.collection.UnmodifiableCollection; 30 import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator; 31 import org.apache.commons.collections.map.UnmodifiableEntrySet; 32 import org.apache.commons.collections.map.UnmodifiableSortedMap; 33 import org.apache.commons.collections.set.UnmodifiableSet; 34 35 43 public final class UnmodifiableSortedBidiMap 44 extends AbstractSortedBidiMapDecorator implements Unmodifiable { 45 46 47 private UnmodifiableSortedBidiMap inverse; 48 49 58 public static SortedBidiMap decorate(SortedBidiMap map) { 59 if (map instanceof Unmodifiable) { 60 return map; 61 } 62 return new UnmodifiableSortedBidiMap(map); 63 } 64 65 72 private UnmodifiableSortedBidiMap(SortedBidiMap map) { 73 super(map); 74 } 75 76 public void clear() { 78 throw new UnsupportedOperationException (); 79 } 80 81 public Object put(Object key, Object value) { 82 throw new UnsupportedOperationException (); 83 } 84 85 public void putAll(Map mapToCopy) { 86 throw new UnsupportedOperationException (); 87 } 88 89 public Object remove(Object key) { 90 throw new UnsupportedOperationException (); 91 } 92 93 public Set entrySet() { 94 Set set = super.entrySet(); 95 return UnmodifiableEntrySet.decorate(set); 96 } 97 98 public Set keySet() { 99 Set set = super.keySet(); 100 return UnmodifiableSet.decorate(set); 101 } 102 103 public Collection values() { 104 Collection coll = super.values(); 105 return UnmodifiableCollection.decorate(coll); 106 } 107 108 public Object removeValue(Object value) { 110 throw new UnsupportedOperationException (); 111 } 112 113 public MapIterator mapIterator() { 114 return orderedMapIterator(); 115 } 116 117 public BidiMap inverseBidiMap() { 118 return inverseSortedBidiMap(); 119 } 120 121 public OrderedMapIterator orderedMapIterator() { 123 OrderedMapIterator it = getSortedBidiMap().orderedMapIterator(); 124 return UnmodifiableOrderedMapIterator.decorate(it); 125 } 126 127 public OrderedBidiMap inverseOrderedBidiMap() { 128 return inverseSortedBidiMap(); 129 } 130 131 public SortedBidiMap inverseSortedBidiMap() { 133 if (inverse == null) { 134 inverse = new UnmodifiableSortedBidiMap(getSortedBidiMap().inverseSortedBidiMap()); 135 inverse.inverse = this; 136 } 137 return inverse; 138 } 139 140 public SortedMap subMap(Object fromKey, Object toKey) { 141 SortedMap sm = getSortedBidiMap().subMap(fromKey, toKey); 142 return UnmodifiableSortedMap.decorate(sm); 143 } 144 145 public SortedMap headMap(Object toKey) { 146 SortedMap sm = getSortedBidiMap().headMap(toKey); 147 return UnmodifiableSortedMap.decorate(sm); 148 } 149 150 public SortedMap tailMap(Object fromKey) { 151 SortedMap sm = getSortedBidiMap().tailMap(fromKey); 152 return UnmodifiableSortedMap.decorate(sm); 153 } 154 155 } 156 | Popular Tags |