1 16 package org.apache.commons.collections.bag; 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.Set ; 25 26 import org.apache.commons.collections.SortedBag; 27 import org.apache.commons.collections.Unmodifiable; 28 import org.apache.commons.collections.iterators.UnmodifiableIterator; 29 import org.apache.commons.collections.set.UnmodifiableSet; 30 31 41 public final class UnmodifiableSortedBag 42 extends AbstractSortedBagDecorator implements Unmodifiable, Serializable { 43 44 45 private static final long serialVersionUID = -3190437252665717841L; 46 47 56 public static SortedBag decorate(SortedBag bag) { 57 if (bag instanceof Unmodifiable) { 58 return bag; 59 } 60 return new UnmodifiableSortedBag(bag); 61 } 62 63 70 private UnmodifiableSortedBag(SortedBag bag) { 71 super(bag); 72 } 73 74 81 private void writeObject(ObjectOutputStream out) throws IOException { 82 out.defaultWriteObject(); 83 out.writeObject(collection); 84 } 85 86 93 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 94 in.defaultReadObject(); 95 collection = (Collection ) in.readObject(); 96 } 97 98 public Iterator iterator() { 100 return UnmodifiableIterator.decorate(getCollection().iterator()); 101 } 102 103 public boolean add(Object object) { 104 throw new UnsupportedOperationException (); 105 } 106 107 public boolean addAll(Collection coll) { 108 throw new UnsupportedOperationException (); 109 } 110 111 public void clear() { 112 throw new UnsupportedOperationException (); 113 } 114 115 public boolean remove(Object object) { 116 throw new UnsupportedOperationException (); 117 } 118 119 public boolean removeAll(Collection coll) { 120 throw new UnsupportedOperationException (); 121 } 122 123 public boolean retainAll(Collection coll) { 124 throw new UnsupportedOperationException (); 125 } 126 127 public boolean add(Object object, int count) { 129 throw new UnsupportedOperationException (); 130 } 131 132 public boolean remove(Object object, int count) { 133 throw new UnsupportedOperationException (); 134 } 135 136 public Set uniqueSet() { 137 Set set = getBag().uniqueSet(); 138 return UnmodifiableSet.decorate(set); 139 } 140 141 } 142 | Popular Tags |