1 16 package org.apache.commons.collections.map; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import org.apache.commons.collections.MapIterator; 27 import org.apache.commons.collections.OrderedMap; 28 import org.apache.commons.collections.OrderedMapIterator; 29 import org.apache.commons.collections.Unmodifiable; 30 import org.apache.commons.collections.collection.UnmodifiableCollection; 31 import org.apache.commons.collections.iterators.UnmodifiableMapIterator; 32 import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator; 33 import org.apache.commons.collections.set.UnmodifiableSet; 34 35 45 public final class UnmodifiableOrderedMap 46 extends AbstractOrderedMapDecorator 47 implements Unmodifiable, Serializable { 48 49 50 private static final long serialVersionUID = 8136428161720526266L; 51 52 58 public static OrderedMap decorate(OrderedMap map) { 59 if (map instanceof Unmodifiable) { 60 return map; 61 } 62 return new UnmodifiableOrderedMap(map); 63 } 64 65 72 private UnmodifiableOrderedMap(OrderedMap map) { 73 super(map); 74 } 75 76 84 private void writeObject(ObjectOutputStream out) throws IOException { 85 out.defaultWriteObject(); 86 out.writeObject(map); 87 } 88 89 97 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 98 in.defaultReadObject(); 99 map = (Map ) in.readObject(); 100 } 101 102 public MapIterator mapIterator() { 104 MapIterator it = getOrderedMap().mapIterator(); 105 return UnmodifiableMapIterator.decorate(it); 106 } 107 108 public OrderedMapIterator orderedMapIterator() { 109 OrderedMapIterator it = getOrderedMap().orderedMapIterator(); 110 return UnmodifiableOrderedMapIterator.decorate(it); 111 } 112 113 public void clear() { 114 throw new UnsupportedOperationException (); 115 } 116 117 public Object put(Object key, Object value) { 118 throw new UnsupportedOperationException (); 119 } 120 121 public void putAll(Map mapToCopy) { 122 throw new UnsupportedOperationException (); 123 } 124 125 public Object remove(Object key) { 126 throw new UnsupportedOperationException (); 127 } 128 129 public Set entrySet() { 130 Set set = super.entrySet(); 131 return UnmodifiableEntrySet.decorate(set); 132 } 133 134 public Set keySet() { 135 Set set = super.keySet(); 136 return UnmodifiableSet.decorate(set); 137 } 138 139 public Collection values() { 140 Collection coll = super.values(); 141 return UnmodifiableCollection.decorate(coll); 142 } 143 144 } 145 | Popular Tags |