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.Comparator ; 24 import java.util.Map ; 25 import java.util.Set ; 26 import java.util.SortedMap ; 27 28 import org.apache.commons.collections.Unmodifiable; 29 import org.apache.commons.collections.collection.UnmodifiableCollection; 30 import org.apache.commons.collections.set.UnmodifiableSet; 31 32 42 public final class UnmodifiableSortedMap 43 extends AbstractSortedMapDecorator 44 implements Unmodifiable, Serializable { 45 46 47 private static final long serialVersionUID = 5805344239827376360L; 48 49 55 public static SortedMap decorate(SortedMap map) { 56 if (map instanceof Unmodifiable) { 57 return map; 58 } 59 return new UnmodifiableSortedMap(map); 60 } 61 62 69 private UnmodifiableSortedMap(SortedMap map) { 70 super(map); 71 } 72 73 81 private void writeObject(ObjectOutputStream out) throws IOException { 82 out.defaultWriteObject(); 83 out.writeObject(map); 84 } 85 86 94 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 95 in.defaultReadObject(); 96 map = (Map ) in.readObject(); 97 } 98 99 public void clear() { 101 throw new UnsupportedOperationException (); 102 } 103 104 public Object put(Object key, Object value) { 105 throw new UnsupportedOperationException (); 106 } 107 108 public void putAll(Map mapToCopy) { 109 throw new UnsupportedOperationException (); 110 } 111 112 public Object remove(Object key) { 113 throw new UnsupportedOperationException (); 114 } 115 116 public Set entrySet() { 117 Set set = super.entrySet(); 118 return UnmodifiableEntrySet.decorate(set); 119 } 120 121 public Set keySet() { 122 Set set = super.keySet(); 123 return UnmodifiableSet.decorate(set); 124 } 125 126 public Collection values() { 127 Collection coll = super.values(); 128 return UnmodifiableCollection.decorate(coll); 129 } 130 131 public Object firstKey() { 133 return getSortedMap().firstKey(); 134 } 135 136 public Object lastKey() { 137 return getSortedMap().lastKey(); 138 } 139 140 public Comparator comparator() { 141 return getSortedMap().comparator(); 142 } 143 144 public SortedMap subMap(Object fromKey, Object toKey) { 145 SortedMap map = getSortedMap().subMap(fromKey, toKey); 146 return new UnmodifiableSortedMap(map); 147 } 148 149 public SortedMap headMap(Object toKey) { 150 SortedMap map = getSortedMap().headMap(toKey); 151 return new UnmodifiableSortedMap(map); 152 } 153 154 public SortedMap tailMap(Object fromKey) { 155 SortedMap map = getSortedMap().tailMap(fromKey); 156 return new UnmodifiableSortedMap(map); 157 } 158 159 } 160 | Popular Tags |