| Home >> All >> jtemporal >> [ util Javadoc ] |
Source code: jtemporal/util/ReadOnlySet.java
1 package jtemporal.util; 2 3 import java.util.*; 4 import java.io.Serializable; 5 6 7 /** 8 * Set proxy, restricting operations to read-only. <BR> 9 * <B>For methods description, see java.util.Set</B> 10 * @author Thomas Beck 11 * @version $Id$ 12 */ 13 14 public class ReadOnlySet implements Set, Serializable { 15 16 private static final String ERROR_MSG = "This Set is read-only"; 17 private static final long serialVersionUID = 9826560106639L; 18 19 private final Set remoteSet; 20 21 public ReadOnlySet(Set s) { 22 this.remoteSet = s; 23 } 24 public boolean contains(Object o) { 25 return remoteSet.contains(o); 26 } 27 public boolean remove(Object o) { 28 throw new UnsupportedOperationException(ERROR_MSG); 29 } 30 public Object[] toArray(Object[] parm1) { 31 return remoteSet.toArray(parm1); 32 } 33 public boolean isEmpty() { 34 return remoteSet.isEmpty(); 35 } 36 public int size() { 37 return remoteSet.size(); 38 } 39 public boolean containsAll(Collection c) { 40 return remoteSet.containsAll(c); 41 } 42 public Object[] toArray() { 43 return remoteSet.toArray(); 44 } 45 46 47 public boolean retainAll(Collection parm1) { 48 throw new UnsupportedOperationException(ERROR_MSG); 49 } 50 public boolean add(Object o) { 51 throw new UnsupportedOperationException(ERROR_MSG); 52 } 53 public void clear() { 54 throw new UnsupportedOperationException(ERROR_MSG); 55 } 56 public Iterator iterator() { 57 return new Iterator() { 58 private final Iterator remoteIterator = ReadOnlySet.this.remoteSet.iterator(); 59 public boolean hasNext() { 60 return remoteIterator.hasNext(); 61 } 62 public Object next() { 63 return remoteIterator.next(); 64 } 65 public void remove() { 66 throw new UnsupportedOperationException(ReadOnlySet.ERROR_MSG); 67 } 68 }; 69 } 70 public boolean addAll(Collection parm1) { 71 throw new UnsupportedOperationException(ERROR_MSG); 72 } 73 public boolean removeAll(Collection parm1) { 74 throw new UnsupportedOperationException(ERROR_MSG); 75 } 76 }