|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList
org.norther.tammi.acorn.util.ArrayAsList
public class ArrayAsList
An array implementation of the List interface avoiding
synchronization by making a new copy of its back-end array whenever it is
structurally modified. The solution consumes memory and is not suitable for
frequently changing lists, but provides a non-blocking container for read
oriented tasks.
Additional methods, addIfAbsent and addAllAbsent, support the
ArrayAsSet implementation of the Set interface
but can be used with this class as well. The copyIn, copyAll and copyAbsent
methods support modification of contents with one operation.
Note that the list maintains the original component type, if any, in all array operations.
Note that iterators don't support other that set modifications.
Based on Doug Lea's CopyOnWriteArrayList .
| Nested Class Summary | |
|---|---|
protected static class |
ArrayAsList.ArrayIterator
An inner class for iterators. |
| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
ArrayAsList()
Constructs an empty list. |
|
ArrayAsList(Collection c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
ArrayAsList(Object[] array)
Constructs a list using the specified array as its back-end and maintaining the component type of the array during modifications. |
|
| Method Summary | |
|---|---|
void |
add(int index,
Object item)
|
boolean |
add(Object item)
|
boolean |
addAll(Collection c)
|
boolean |
addAll(int index,
Collection c)
|
int |
addAllAbsent(Collection collection)
Adds all items in the specified collection that are not already contained in this list, to the end of this list, in the order that they are returned by the specified collection's toArray method. |
int |
addAllAbsent(int index,
Collection c)
Adds all items in the specified collection that are not already contained in this list, at the specified position of this list, in the order that they are returned by the specified collection's toArray method. |
boolean |
addIfAbsent(int index,
Object item)
Adds the specified item at the specified position in this list if it is not present. |
boolean |
addIfAbsent(Object item)
Adds the specified item to the end of this list if it is not present. |
void |
clear()
|
Object |
clone()
Clones this list by returning a shallow copy. |
boolean |
contains(Object item)
|
boolean |
containsAll(Collection c)
|
int |
copyAbsent(int index,
Object[] source)
Copies missing elements from the specified array to the given position of the back-end. |
int |
copyAbsent(Object[] source)
Copies missing elements from the specified array to the back-end. |
void |
copyAll(int index,
Object[] source)
Copies all elements from the specified array to the given position of the back-end. |
void |
copyAll(Object[] source)
Copies all elements from the specified array to the back-end. |
Object |
get(int index)
|
Object[] |
getArray()
Gets a snapshot of the back-end array. |
Class |
getComponentType()
Gets the component type of the back-end array. |
int |
indexOf(Object item)
|
protected static int |
indexOf(Object item,
Object[] array,
int offset,
int n)
A static index method without synchronization. |
Iterator |
iterator()
|
int |
lastIndexOf(Object item)
|
ListIterator |
listIterator()
|
ListIterator |
listIterator(int index)
|
protected static void |
rangeCheck(int index,
int length)
Checks if the given index is in range. |
Object |
remove(int index)
|
boolean |
remove(Object item)
|
boolean |
removeAll(Collection c)
|
void |
removeRange(int fromIndex,
int toIndex)
Removes a range of elements from this list in one operation. |
boolean |
retainAll(Collection c)
|
Object |
set(int index,
Object item)
|
void |
setArray(Object[] array)
Sets the the back-end array. |
void |
setSize(int size)
Sets the size of the back-end array by adding nulls or by truncating. |
int |
size()
|
Object[] |
toArray()
|
Object[] |
toArray(Object[] a)
|
| Methods inherited from class java.util.AbstractList |
|---|
equals, hashCode, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
isEmpty, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
isEmpty |
| Constructor Detail |
|---|
public ArrayAsList()
public ArrayAsList(Collection c)
c - the collection whose elements are to be copied.public ArrayAsList(Object[] array)
array - the array, which is used as the internal array.| Method Detail |
|---|
protected static int indexOf(Object item,
Object[] array,
int offset,
int n)
item - the item to search.array - the array of items.offset - the start index.n - the number of items to iterate.
protected static void rangeCheck(int index,
int length)
index - the index to check.length - the number of items.
IndexOutOfBoundsException - on errors.public Object clone()
clone in class Objectpublic void copyAll(Object[] source)
source - the array to copy.
public void copyAll(int index,
Object[] source)
index - the index of the elements.source - the array to copy.
IndexOutOfBoundsException - for invalid index.public int copyAbsent(Object[] source)
source - the array to copy.
public int copyAbsent(int index,
Object[] source)
index - the index of the elements.source - the array to copy.
IndexOutOfBoundsException - for invalid index.public boolean addIfAbsent(Object item)
item - the item to be added.
public boolean addIfAbsent(int index,
Object item)
index - the index of the item.item - the item to be inserted.
IndexOutOfBoundsException - for invalid index.public int addAllAbsent(Collection collection)
collection - the items to be added.
public int addAllAbsent(int index,
Collection c)
index - the index of the item.c - the items to be added.
public void removeRange(int fromIndex,
int toIndex)
removeRange in class AbstractListfromIndex - index of first element to be removed.toIndex - index after last element to be removed.public void setSize(int size)
size - the new size.public Object[] getArray()
public void setArray(Object[] array)
array - the back-end array.public Class getComponentType()
public int size()
size in interface Collectionsize in interface Listsize in class AbstractCollectionpublic boolean contains(Object item)
contains in interface Collectioncontains in interface Listcontains in class AbstractCollectionpublic boolean containsAll(Collection c)
containsAll in interface CollectioncontainsAll in interface ListcontainsAll in class AbstractCollectionpublic int indexOf(Object item)
indexOf in interface ListindexOf in class AbstractListpublic int lastIndexOf(Object item)
lastIndexOf in interface ListlastIndexOf in class AbstractListpublic Object[] toArray()
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectionpublic Object[] toArray(Object[] a)
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectionpublic Object get(int index)
get in interface Listget in class AbstractList
public Object set(int index,
Object item)
set in interface Listset in class AbstractListpublic boolean add(Object item)
add in interface Collectionadd in interface Listadd in class AbstractList
public void add(int index,
Object item)
add in interface Listadd in class AbstractListpublic Object remove(int index)
remove in interface Listremove in class AbstractListpublic boolean remove(Object item)
remove in interface Collectionremove in interface Listremove in class AbstractCollectionpublic void clear()
clear in interface Collectionclear in interface Listclear in class AbstractListpublic boolean addAll(Collection c)
addAll in interface CollectionaddAll in interface ListaddAll in class AbstractCollection
public boolean addAll(int index,
Collection c)
addAll in interface ListaddAll in class AbstractListpublic boolean removeAll(Collection c)
removeAll in interface CollectionremoveAll in interface ListremoveAll in class AbstractCollectionpublic boolean retainAll(Collection c)
retainAll in interface CollectionretainAll in interface ListretainAll in class AbstractCollectionpublic Iterator iterator()
iterator in interface Iterableiterator in interface Collectioniterator in interface Listiterator in class AbstractListpublic ListIterator listIterator()
listIterator in interface ListlistIterator in class AbstractListpublic ListIterator listIterator(int index)
listIterator in interface ListlistIterator in class AbstractList
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||