org.norther.tammi.acorn.util
Class WeakArrayList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.norther.tammi.acorn.util.WeakArrayList<E>
Type Parameters:
E - the element type.
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public class WeakArrayList<E>
extends AbstractList<E>
implements List<E>

A variation of ArrayAsList storing internally its elements as weak references.

Version:
$Id: WeakArrayList.java,v 1.6 2009/10/29 21:44:08 cvsimp Exp $
Author:
Ilkka Priha

Nested Class Summary
protected static class WeakArrayList.ReferenceIterator<E>
          An inner class for iterators.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
WeakArrayList()
          Constructs an empty collection.
WeakArrayList(Collection<? extends E> c)
          Constructs a new collection.
 
Method Summary
 boolean add(E item)
           
 void add(int index, E item)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void clear()
           
 boolean contains(Object item)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 E get(int index)
           
protected  ArrayAsList<WeakReference<E>> getArrayAsList()
          Gets the list adaptee.
 int hashCode()
           
 int indexOf(Object item)
           
protected static int indexOf(Object item, WeakReference<?>[] array, int offset, int n)
          A static index method without synchronization.
 Iterator<E> iterator()
           
 int lastIndexOf(Object item)
           
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 E remove(int index)
           
 boolean remove(Object item)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 E set(int index, E item)
           
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.util.AbstractList
removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
isEmpty, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
isEmpty, subList
 

Constructor Detail

WeakArrayList

public WeakArrayList()
Constructs an empty collection.


WeakArrayList

public WeakArrayList(Collection<? extends E> c)
Constructs a new collection.

Parameters:
c - a collection to wrap.
Method Detail

indexOf

protected static int indexOf(Object item,
                             WeakReference<?>[] array,
                             int offset,
                             int n)
A static index method without synchronization.

Parameters:
item - the item to search.
array - the array of items.
offset - the start index.
n - the number of items to iterate.
Returns:
the index of the found item or -1.

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Specified by:
equals in interface List<E>
Overrides:
equals in class AbstractList<E>

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface List<E>
Overrides:
hashCode in class AbstractList<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>

contains

public boolean contains(Object item)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>
Overrides:
contains in class AbstractCollection<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface List<E>
Overrides:
containsAll in class AbstractCollection<E>

indexOf

public int indexOf(Object item)
Specified by:
indexOf in interface List<E>
Overrides:
indexOf in class AbstractList<E>

lastIndexOf

public int lastIndexOf(Object item)
Specified by:
lastIndexOf in interface List<E>
Overrides:
lastIndexOf in class AbstractList<E>

get

public E get(int index)
Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>

set

public E set(int index,
             E item)
Specified by:
set in interface List<E>
Overrides:
set in class AbstractList<E>

add

public boolean add(E item)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>

add

public void add(int index,
                E item)
Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractList<E>

remove

public boolean remove(Object item)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractCollection<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class AbstractList<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractCollection<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractList<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>
Overrides:
removeAll in class AbstractCollection<E>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface List<E>
Overrides:
retainAll in class AbstractCollection<E>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface List<E>
Overrides:
iterator in class AbstractList<E>

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>
Overrides:
listIterator in class AbstractList<E>

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E>
Overrides:
listIterator in class AbstractList<E>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>

getArrayAsList

protected ArrayAsList<WeakReference<E>> getArrayAsList()
Gets the list adaptee.

Returns:
the wrapped list.


Copyright © 2004 The Norther Organization. All rights reserved.