org.scijava.util
Class ObjectArray<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<BaseType>
          extended by org.scijava.util.AbstractPrimitiveArray<E[],E>
              extended by org.scijava.util.ObjectArray<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, PrimitiveArray<E[],E>, Sizable

public class ObjectArray<E>
extends AbstractPrimitiveArray<E[],E>

An extensible, generic array of Object elements. Note that this class is a PrimitiveArray but of course Objects are not primitives. However, this class still facilitates improved conversion of Object array types to collections, and thus remains useful (if not completely accurately congruent with its type hierarchy).

This class still provides a convenient way to work around Arrays.asList(Object...) creating a list with a single element. It also contains improved performance implementations of many Collection methods.

Author:
Mark Hiner, Johannes Schindelin, Curtis Rueden

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ObjectArray(Class<E> arrayType)
          Constructs an extensible array of objects, backed by a fixed-size array.
ObjectArray(Class<E> arrayType, int size)
          Constructs an extensible array of objects, backed by a fixed-size array.
ObjectArray(E[] array)
          Constructs an extensible array of objects, backed by the given fixed-size array.
 
Method Summary
 void add(int index, E element)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void addValue(E value)
           
 void addValue(int index, E value)
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 E defaultValue()
           
 E get(int index)
           
 E[] getArray()
          Gets the fixed-size array backing this instance.
 E getValue(int index)
           
 int indexOf(Object o)
           
 int lastIndexOf(Object o)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean removeValue(E value)
           
 E set(int index, E element)
           
 void setArray(E[] array)
          Sets the fixed-size array backing this instance.
 E setValue(int index, E value)
           
 
Methods inherited from class org.scijava.util.AbstractPrimitiveArray
capacity, checkBounds, clear, copyArray, delete, ensureCapacity, getMaximumGrowth, insert, remove, setMaximumGrowth, setSize, size
 
Methods inherited from class java.util.AbstractList
add, equals, hashCode, iterator, listIterator, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, equals, hashCode, isEmpty, iterator, listIterator, listIterator, retainAll, subList, toArray, toArray
 

Constructor Detail

ObjectArray

public ObjectArray(Class<E> arrayType)
Constructs an extensible array of objects, backed by a fixed-size array.


ObjectArray

public ObjectArray(Class<E> arrayType,
                   int size)
Constructs an extensible array of objects, backed by a fixed-size array.

Parameters:
size - the initial size

ObjectArray

public ObjectArray(E[] array)
Constructs an extensible array of objects, backed by the given fixed-size array.

Parameters:
array - the array to wrap
Method Detail

addValue

public void addValue(E value)

removeValue

public boolean removeValue(E value)

getValue

public E getValue(int index)

setValue

public E setValue(int index,
                  E value)

addValue

public void addValue(int index,
                     E value)

getArray

public E[] getArray()
Description copied from interface: PrimitiveArray
Gets the fixed-size array backing this instance.

Returns:
the backing array

setArray

public void setArray(E[] array)
Description copied from interface: PrimitiveArray
Sets the fixed-size array backing this instance.

Parameters:
array - the new backing array

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 element)
Specified by:
set in interface List<E>
Specified by:
set in class AbstractPrimitiveArray<E[],E>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>
Specified by:
add in class AbstractPrimitiveArray<E[],E>

indexOf

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

lastIndexOf

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

contains

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

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove 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>

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>

defaultValue

public E defaultValue()


Copyright © 2009–2015 SciJava. All rights reserved.