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.BoundedCollection; 24 import org.apache.commons.collections.iterators.AbstractListIteratorDecorator; 25 import org.apache.commons.collections.iterators.UnmodifiableIterator; 26 27 41 public class FixedSizeList 42 extends AbstractSerializableListDecorator 43 implements BoundedCollection { 44 45 46 private static final long serialVersionUID = -2218010673611160319L; 47 48 54 public static List decorate(List list) { 55 return new FixedSizeList(list); 56 } 57 58 65 protected FixedSizeList(List list) { 66 super(list); 67 } 68 69 public boolean add(Object object) { 71 throw new UnsupportedOperationException ("List is fixed size"); 72 } 73 74 public void add(int index, Object object) { 75 throw new UnsupportedOperationException ("List is fixed size"); 76 } 77 78 public boolean addAll(Collection coll) { 79 throw new UnsupportedOperationException ("List is fixed size"); 80 } 81 82 public boolean addAll(int index, Collection coll) { 83 throw new UnsupportedOperationException ("List is fixed size"); 84 } 85 86 public void clear() { 87 throw new UnsupportedOperationException ("List is fixed size"); 88 } 89 90 public Object get(int index) { 91 return getList().get(index); 92 } 93 94 public int indexOf(Object object) { 95 return getList().indexOf(object); 96 } 97 98 public Iterator iterator() { 99 return UnmodifiableIterator.decorate(getCollection().iterator()); 100 } 101 102 public int lastIndexOf(Object object) { 103 return getList().lastIndexOf(object); 104 } 105 106 public ListIterator listIterator() { 107 return new FixedSizeListIterator(getList().listIterator(0)); 108 } 109 110 public ListIterator listIterator(int index) { 111 return new FixedSizeListIterator(getList().listIterator(index)); 112 } 113 114 public Object remove(int index) { 115 throw new UnsupportedOperationException ("List is fixed size"); 116 } 117 118 public boolean remove(Object object) { 119 throw new UnsupportedOperationException ("List is fixed size"); 120 } 121 122 public boolean removeAll(Collection coll) { 123 throw new UnsupportedOperationException ("List is fixed size"); 124 } 125 126 public boolean retainAll(Collection coll) { 127 throw new UnsupportedOperationException ("List is fixed size"); 128 } 129 130 public Object set(int index, Object object) { 131 return getList().set(index, object); 132 } 133 134 public List subList(int fromIndex, int toIndex) { 135 List sub = getList().subList(fromIndex, toIndex); 136 return new FixedSizeList(sub); 137 } 138 139 142 static class FixedSizeListIterator extends AbstractListIteratorDecorator { 143 protected FixedSizeListIterator(ListIterator iterator) { 144 super(iterator); 145 } 146 public void remove() { 147 throw new UnsupportedOperationException ("List is fixed size"); 148 } 149 public void add(Object object) { 150 throw new UnsupportedOperationException ("List is fixed size"); 151 } 152 } 153 154 public boolean isFull() { 155 return true; 156 } 157 158 public int maxSize() { 159 return size(); 160 } 161 162 } 163 | Popular Tags |