[Jboss-cvs] JBossAS SVN: r54987 - trunk/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:43 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-01 13:43:43 -0400 (Tue, 01 Aug 2006)
New Revision: 54987

Added:
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java
Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
Log:
[JBAS-2225] ImmutableArrayList uses delegation and serializes the delegate via writeReplace()

Modified: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java	2006-08-01 17:43:22 UTC (rev 54986)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java	2006-08-01 17:43:43 UTC (rev 54987)
@@ -167,152 +167,4 @@
    
    // Inner classes -------------------------------------------------
    
-   private class ImmutableArrayList extends ArrayList
-   {
-      /** The serialVersionUID */
-      private static final long serialVersionUID = -991188901511748496L;
-
-      ImmutableArrayList(ArrayList source)
-      {
-         super(source);
-      }
-      
-      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");
-      }      
-      
-   }
-   
-   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");         
-      }
-      
-   }
 }

Added: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java	2006-08-01 17:43:22 UTC (rev 54986)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ImmutableArrayList.java	2006-08-01 17:43:43 UTC (rev 54987)
@@ -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