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 22 import org.apache.commons.collections.BidiMap; 23 import org.apache.commons.collections.MapIterator; 24 import org.apache.commons.collections.Unmodifiable; 25 import org.apache.commons.collections.collection.UnmodifiableCollection; 26 import org.apache.commons.collections.iterators.UnmodifiableMapIterator; 27 import org.apache.commons.collections.map.UnmodifiableEntrySet; 28 import org.apache.commons.collections.set.UnmodifiableSet; 29 30 38 public final class UnmodifiableBidiMap 39 extends AbstractBidiMapDecorator implements Unmodifiable { 40 41 42 private UnmodifiableBidiMap inverse; 43 44 53 public static BidiMap decorate(BidiMap map) { 54 if (map instanceof Unmodifiable) { 55 return map; 56 } 57 return new UnmodifiableBidiMap(map); 58 } 59 60 67 private UnmodifiableBidiMap(BidiMap map) { 68 super(map); 69 } 70 71 public void clear() { 73 throw new UnsupportedOperationException (); 74 } 75 76 public Object put(Object key, Object value) { 77 throw new UnsupportedOperationException (); 78 } 79 80 public void putAll(Map mapToCopy) { 81 throw new UnsupportedOperationException (); 82 } 83 84 public Object remove(Object key) { 85 throw new UnsupportedOperationException (); 86 } 87 88 public Set entrySet() { 89 Set set = super.entrySet(); 90 return UnmodifiableEntrySet.decorate(set); 91 } 92 93 public Set keySet() { 94 Set set = super.keySet(); 95 return UnmodifiableSet.decorate(set); 96 } 97 98 public Collection values() { 99 Collection coll = super.values(); 100 return UnmodifiableCollection.decorate(coll); 101 } 102 103 public Object removeValue(Object value) { 105 throw new UnsupportedOperationException (); 106 } 107 108 public MapIterator mapIterator() { 109 MapIterator it = getBidiMap().mapIterator(); 110 return UnmodifiableMapIterator.decorate(it); 111 } 112 113 public BidiMap inverseBidiMap() { 114 if (inverse == null) { 115 inverse = new UnmodifiableBidiMap(getBidiMap().inverseBidiMap()); 116 inverse.inverse = this; 117 } 118 return inverse; 119 } 120 121 } 122 | Popular Tags |