[Jboss-cvs] JBossAS SVN: r54986 - branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 1 13:43:23 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-08-01 13:43:22 -0400 (Tue, 01 Aug 2006)
New Revision: 54986
Added:
branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java
Log:
[JBAS-2225] ImmutableArrayList uses delegation and serializes the delegate via writeReplace()
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java 2006-08-01 17:38:44 UTC (rev 54985)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java 2006-08-01 17:43:22 UTC (rev 54986)
@@ -0,0 +1,256 @@
+package org.jboss.ha.framework.interfaces;
+
+import java.io.ObjectStreamException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Subclasses ArrayList but throws an UnsupportedOperationException from
+ * any method that would change the internal data members. Any iterators
+ * that are returned do the same.
+ *
+ * All other methods are delegated to the ArrayList that is passed to the
+ * constructor, so creating an instance of this class does not result in
+ * making a copy of the internal element array of the source array list.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class ImmutableArrayList extends ArrayList
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7080841600873898901L;
+
+ private ArrayList delegate;
+
+ ImmutableArrayList(ArrayList source)
+ {
+ this.delegate = source;
+ }
+
+ // Delegated Methods
+
+ public Object clone()
+ {
+ return delegate.clone();
+ }
+
+ public boolean contains(Object elem)
+ {
+ return delegate.contains(elem);
+ }
+
+ public Object get(int index)
+ {
+ return delegate.get(index);
+ }
+
+ public int indexOf(Object elem)
+ {
+ return delegate.indexOf(elem);
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.isEmpty();
+ }
+
+ public int lastIndexOf(Object elem)
+ {
+ return delegate.lastIndexOf(elem);
+ }
+
+ public int size()
+ {
+ return delegate.size();
+ }
+
+ public Object[] toArray()
+ {
+ return delegate.toArray();
+ }
+
+ public Object[] toArray(Object[] a)
+ {
+ return delegate.toArray(a);
+ }
+
+ public boolean equals(Object o)
+ {
+ return delegate.equals(o);
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public List subList(int fromIndex, int toIndex)
+ {
+ return delegate.subList(fromIndex, toIndex);
+ }
+
+ public boolean containsAll(Collection c)
+ {
+ return delegate.containsAll(c);
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+
+ // Immutable Methods
+
+ public void add(int arg0, Object arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean add(Object arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean addAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean addAll(int arg0, Collection arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void ensureCapacity(int arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Object remove(int arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean remove(Object arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ protected void removeRange(int arg0, int arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Object set(int arg0, Object arg1)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public void trimToSize()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public Iterator iterator()
+ {
+ return new ImmutableArrayListIterator(super.listIterator());
+ }
+
+ public ListIterator listIterator()
+ {
+ return new ImmutableArrayListIterator(super.listIterator());
+ }
+
+ public ListIterator listIterator(int index)
+ {
+ return new ImmutableArrayListIterator(super.listIterator(index));
+ }
+
+ public boolean removeAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean retainAll(Collection arg0)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ // Serialization
+
+ private Object writeReplace() throws ObjectStreamException
+ {
+ return delegate;
+ }
+
+ // Inner Classes
+
+ private class ImmutableArrayListIterator implements ListIterator
+ {
+
+
+ private ListIterator delegate;
+
+ ImmutableArrayListIterator(ListIterator delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Object next()
+ {
+ return delegate.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+
+ }
+
+ public void add(Object o)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ public boolean hasPrevious()
+ {
+ return delegate.hasPrevious();
+ }
+
+ public int nextIndex()
+ {
+ return delegate.nextIndex();
+ }
+
+ public Object previous()
+ {
+ return delegate.previous();
+ }
+
+ public int previousIndex()
+ {
+ return delegate.previousIndex();
+ }
+
+ public void set(Object o)
+ {
+ throw new UnsupportedOperationException("Target list is immutable; mutator methods are not supported");
+ }
+
+ }
+
+}
More information about the jboss-cvs-commits
mailing list