You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/05/09 18:39:23 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/decorators FixedSizeList.java
scolebourne 2003/05/09 09:39:23
Modified: collections/src/java/org/apache/commons/collections/decorators
FixedSizeList.java
Log:
Change to extend AbstractListDecorator (better superclass)
Revision Changes Path
1.5 +41 -19 jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/FixedSizeList.java
Index: FixedSizeList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/FixedSizeList.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FixedSizeList.java 7 May 2003 12:18:55 -0000 1.4
+++ FixedSizeList.java 9 May 2003 16:39:23 -0000 1.5
@@ -58,9 +58,12 @@
package org.apache.commons.collections.decorators;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.apache.commons.collections.IteratorUtils;
+
/**
* <code>FixedSizeList</code> decorates another <code>List</code>
* to fix the size.
@@ -74,7 +77,7 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class FixedSizeList extends UnmodifiableCollection implements List {
+public class FixedSizeList extends AbstractListDecorator {
/**
* Factory method to create a fixed size list.
@@ -96,22 +99,25 @@
super(list);
}
- /**
- * Gets the list being decorated.
- *
- * @return the decorated list
- */
- protected List getList() {
- return (List) getCollection();
+ //-----------------------------------------------------------------------
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException("List is fixed size");
}
- //-----------------------------------------------------------------------
public void add(int index, Object object) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException("List is fixed size");
}
public boolean addAll(int index, Collection coll) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException("List is fixed size");
}
public Object get(int index) {
@@ -122,12 +128,16 @@
return getList().indexOf(object);
}
+ public Iterator iterator() {
+ return IteratorUtils.unmodifiableIterator(getCollection().iterator());
+ }
+
public int lastIndexOf(Object object) {
return getList().lastIndexOf(object);
}
public ListIterator listIterator() {
- return listIterator(0);
+ return new FixedSizeListIterator(getList().listIterator(0));
}
public ListIterator listIterator(int index) {
@@ -135,7 +145,19 @@
}
public Object remove(int index) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException("List is fixed size");
+ }
+
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException("List is fixed size");
+ }
+
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException("List is fixed size");
}
public Object set(int index, Object object) {
@@ -150,18 +172,18 @@
/**
* List iterator that only permits changes via set()
*/
- public static class FixedSizeListIterator extends AbstractListIteratorDecorator {
+ protected static class FixedSizeListIterator extends AbstractListIteratorDecorator {
protected FixedSizeListIterator(ListIterator iterator) {
super(iterator);
}
public void remove() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
}
public void add(Object object) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
}
public void remove(Object object) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("List is fixed size");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org