SE450: Proxy: Unmodifiable Collection [1/13] Previous pageContentsNext page

file:UnmodifiableCollection.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package proxy;
import java.util.Collection;
import java.util.Iterator;
import java.io.Serializable;

@SuppressWarnings("serial")
class UnmodifiableCollection<E> implements Collection<E>, Serializable {
  Collection<E> c;

  UnmodifiableCollection(Collection<E> c) {
    if (c==null)
      throw new NullPointerException();
    this.c = c;
  }

  public int      size()                       {return c.size();}
  public boolean  isEmpty()                    {return c.isEmpty();}
  public boolean  contains(Object o)           {return c.contains(o);}
  public Object[] toArray()                    {return c.toArray();}
  public <T> T[]  toArray(T[] a)               {return c.toArray(a);}
  public String   toString()                   {return c.toString();}
  public boolean  containsAll(Collection<?> d) {return c.containsAll(d);}

  public Iterator<E> iterator() {
    return new Iterator<E>() {
      Iterator<E> i = UnmodifiableCollection.this.c.iterator();

      public boolean hasNext() {return i.hasNext();}
      public E next()          {return i.next();}
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }

  public boolean add(Object o){
    throw new UnsupportedOperationException();
  }
  public boolean remove(Object o) {
    throw new UnsupportedOperationException();
  }
  public boolean addAll(Collection<? extends E> c) {
    throw new UnsupportedOperationException();
  }
  public boolean removeAll(Collection<?> c) {
    throw new UnsupportedOperationException();
  }
  public boolean retainAll(Collection<?> c) {
    throw new UnsupportedOperationException();
  }
  public void clear() {
    throw new UnsupportedOperationException();
  }
}

Previous pageContentsNext page