1 16 package org.apache.commons.collections.list; 17 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.ListIterator ; 22 23 import org.apache.commons.collections.Unmodifiable; 24 import org.apache.commons.collections.iterators.UnmodifiableIterator; 25 import org.apache.commons.collections.iterators.UnmodifiableListIterator; 26 27 37 public final class UnmodifiableList 38 extends AbstractSerializableListDecorator 39 implements Unmodifiable { 40 41 42 private static final long serialVersionUID = 6595182819922443652L; 43 44 50 public static List decorate(List list) { 51 if (list instanceof Unmodifiable) { 52 return list; 53 } 54 return new UnmodifiableList(list); 55 } 56 57 64 private UnmodifiableList(List list) { 65 super(list); 66 } 67 68 public Iterator iterator() { 70 return UnmodifiableIterator.decorate(getCollection().iterator()); 71 } 72 73 public boolean add(Object object) { 74 throw new UnsupportedOperationException (); 75 } 76 77 public boolean addAll(Collection coll) { 78 throw new UnsupportedOperationException (); 79 } 80 81 public void clear() { 82 throw new UnsupportedOperationException (); 83 } 84 85 public boolean remove(Object object) { 86 throw new UnsupportedOperationException (); 87 } 88 89 public boolean removeAll(Collection coll) { 90 throw new UnsupportedOperationException (); 91 } 92 93 public boolean retainAll(Collection coll) { 94 throw new UnsupportedOperationException (); 95 } 96 97 public ListIterator listIterator() { 99 return UnmodifiableListIterator.decorate(getList().listIterator()); 100 } 101 102 public ListIterator listIterator(int index) { 103 return UnmodifiableListIterator.decorate(getList().listIterator(index)); 104 } 105 106 public void add(int index, Object object) { 107 throw new UnsupportedOperationException (); 108 } 109 110 public boolean addAll(int index, Collection coll) { 111 throw new UnsupportedOperationException (); 112 } 113 114 public Object remove(int index) { 115 throw new UnsupportedOperationException (); 116 } 117 118 public Object set(int index, Object object) { 119 throw new UnsupportedOperationException (); 120 } 121 122 public List subList(int fromIndex, int toIndex) { 123 List sub = getList().subList(fromIndex, toIndex); 124 return new UnmodifiableList(sub); 125 } 126 127 } 128 | Popular Tags |