1 16 package org.apache.commons.collections.set; 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.Iterator ; 24 import java.util.SortedSet ; 25 26 import org.apache.commons.collections.Unmodifiable; 27 import org.apache.commons.collections.iterators.UnmodifiableIterator; 28 29 39 public final class UnmodifiableSortedSet 40 extends AbstractSortedSetDecorator 41 implements Unmodifiable, Serializable { 42 43 44 private static final long serialVersionUID = -725356885467962424L; 45 46 52 public static SortedSet decorate(SortedSet set) { 53 if (set instanceof Unmodifiable) { 54 return set; 55 } 56 return new UnmodifiableSortedSet(set); 57 } 58 59 66 private void writeObject(ObjectOutputStream out) throws IOException { 67 out.defaultWriteObject(); 68 out.writeObject(collection); 69 } 70 71 78 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 79 in.defaultReadObject(); 80 collection = (Collection ) in.readObject(); 81 } 82 83 90 private UnmodifiableSortedSet(SortedSet set) { 91 super(set); 92 } 93 94 public Iterator iterator() { 96 return UnmodifiableIterator.decorate(getCollection().iterator()); 97 } 98 99 public boolean add(Object object) { 100 throw new UnsupportedOperationException (); 101 } 102 103 public boolean addAll(Collection coll) { 104 throw new UnsupportedOperationException (); 105 } 106 107 public void clear() { 108 throw new UnsupportedOperationException (); 109 } 110 111 public boolean remove(Object object) { 112 throw new UnsupportedOperationException (); 113 } 114 115 public boolean removeAll(Collection coll) { 116 throw new UnsupportedOperationException (); 117 } 118 119 public boolean retainAll(Collection coll) { 120 throw new UnsupportedOperationException (); 121 } 122 123 public SortedSet subSet(Object fromElement, Object toElement) { 125 SortedSet sub = getSortedSet().subSet(fromElement, toElement); 126 return new UnmodifiableSortedSet(sub); 127 } 128 129 public SortedSet headSet(Object toElement) { 130 SortedSet sub = getSortedSet().headSet(toElement); 131 return new UnmodifiableSortedSet(sub); 132 } 133 134 public SortedSet tailSet(Object fromElement) { 135 SortedSet sub = getSortedSet().tailSet(fromElement); 136 return new UnmodifiableSortedSet(sub); 137 } 138 139 } 140 | Popular Tags |