public class ImmutableArrayList extends AbstractList implements Collection, List, Set, SortedSet, Comparable, Cloneable, ExternalizableLite
This class also implements the Set interface, although the contents are not checked to determine whether each element is unique. It is the responsibility of the user to ensure that the elements are unique if the object is used as a Set.
Note: while preserved for backward compatibility, as of Coherence 3.6, use of
this class specifically as a List or a Set is deprecated. Instead, the
getList()
, getSet()
, and getSortedSet()
methods
should be used.
Modifier and Type | Class and Description |
---|---|
protected class |
ImmutableArrayList.ListView
ListView exposes the underlying ImmutableArrayList through the
List interface, maintaining correct equals() and
hashCode() semantics |
protected class |
ImmutableArrayList.SetView
SetView exposes the underlying ImmutableArrayList through the
Set interface, maintaining correct equals() and
hashCode() semantics |
protected class |
ImmutableArrayList.SortedSetView
SetView exposes the underlying ImmutableArrayList through the
SortedSet interface, maintaining correct equals() and
hashCode() semantics |
modCount
Constructor and Description |
---|
ImmutableArrayList()
Default constructor (necessary for the ExternalizableLite interface).
|
ImmutableArrayList(Collection collection)
Construct a List containing the elements of the specified Collection.
|
ImmutableArrayList(Object[] ao)
Construct a List from an array.
|
ImmutableArrayList(Object[] ao,
int of,
int c)
Construct a List from a specified number of items in an array starting at
the specified offset.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Create a clone of the ImmutableArrayList.
|
Comparator |
comparator()
Returns the comparator associated with this sorted set, or
null if it uses its elements' natural ordering.
|
int |
compareTo(Object o)
Compare this ImmutableArrayList with the passed Object to determine
order.
|
boolean |
contains(Object o)
Returns true if this List contains the specified element.
|
boolean |
equals(Object o)
Compare this Collection / List / Set / SortedSet with some other Object
and determine if the caller would believe this Object to equal that
other Object.
|
Object |
first()
Returns the first element currently in this sorted set.
|
Object |
get(int i)
Returns the element at the specified position in this List.
|
List |
getList()
Return a java.util.List view of this ImmutableArrayList.
|
Set |
getSet()
Return a java.util.Set view of this ImmutableArrayList.
|
SortedSet |
getSortedSet()
Return a java.util.SortedSet view of this ImmutableArrayList.
|
protected Map |
getValueIndex()
Create a reverse index from value to position if this List is big
enough to warrant it.
|
SortedSet |
headSet(Object toElement)
Returns a view of the portion of this sorted set whose elements are
found in the set in a position before toElement.
|
int |
indexOf(Object o)
Returns the index in this List of the first occurrence of the specified
element, or -1 if this List does not contain this element.
|
Iterator |
iterator()
Returns an iterator over the elements in this list in proper
sequence.
|
Object |
last()
Returns the last element currently in this sorted set.
|
int |
lastIndexOf(Object o)
Returns the index in this List of the last occurrence of the specified
element, or -1 if this List does not contain this element.
|
void |
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from
the passed DataInput object.
|
int |
size()
Returns the number of elements in this List.
|
Spliterator |
spliterator() |
SortedSet |
subSet(Object fromElement,
Object toElement)
Returns a view of the portion of this sorted set whose elements are
found in the set in a position at and after the position of
fromElement and in a position before toElement.
|
SortedSet |
tailSet(Object fromElement)
Returns a view of the portion of this sorted set whose elements are
found in the set in a position at and after the position of
fromElement.
|
Object[] |
toArray()
Returns an array containing all of the elements in this List in the
order that the elements occur in the List.
|
Object[] |
toArray(Object[] ao)
Returns an array with ao runtime type is that of the specified array and
that contains all of the elements in this List.
|
void |
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into
the passed DataOutput object.
|
add, add, addAll, clear, hashCode, listIterator, listIterator, remove, removeRange, set, subList
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
add, add, addAll, addAll, clear, containsAll, hashCode, isEmpty, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, subList
parallelStream, removeIf, stream
public ImmutableArrayList(Object[] ao, int of, int c)
ao
- a non-null array of Objectsof
- an offset of the first item in the arrayc
- the number of items to usepublic ImmutableArrayList(Object[] ao)
ao
- a non-null array of Objectspublic ImmutableArrayList(Collection collection)
collection
- the Collection to fill this List frompublic ImmutableArrayList()
public List getList()
public Set getSet()
Note: this method does not ensure that the underlying ImmutableArrayList adheres to the Set contract. It is the responsibility of the user to ensure that the elements are unique if the object is used as a Set.
public SortedSet getSortedSet()
Note: this method does not ensure that the underlying ImmutableArrayList adheres to the SortedSet contract. It is the responsibility of the user to ensure that the elements are unique and ordered if the object is used as a SortedSet.
public Spliterator spliterator()
spliterator
in interface Iterable
spliterator
in interface Collection
spliterator
in interface List
spliterator
in interface Set
spliterator
in interface SortedSet
public int size()
size
in interface Collection
size
in interface List
size
in interface Set
size
in class AbstractCollection
public Object get(int i)
get
in interface List
get
in class AbstractList
i
- the index of the element to returnIndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public int indexOf(Object o)
indexOf
in interface List
indexOf
in class AbstractList
o
- element to search for.public int lastIndexOf(Object o)
lastIndexOf
in interface List
lastIndexOf
in class AbstractList
o
- element to search for.public boolean contains(Object o)
contains
in interface Collection
contains
in interface List
contains
in interface Set
contains
in class AbstractCollection
o
- element whose presence in this List is to be testedpublic Object[] toArray()
toArray
in interface Collection
toArray
in interface List
toArray
in interface Set
toArray
in class AbstractCollection
public Object[] toArray(Object[] ao)
If the List fits in the specified array with room to spare (i.e., the array has more elements than the List), the element in the array immediately following the end of the last element is set to null. This is useful in determining the length of the List only if the caller knows that the List does not contain any null elements.)
toArray
in interface Collection
toArray
in interface List
toArray
in interface Set
toArray
in class AbstractCollection
ao
- the array into which the elements of the List are to be
stored, if it is big enough; otherwise, ao new array of the
same runtime type is allocated for this purposeArrayStoreException
- if the runtime type of the specified array
is not ao supertype of the runtime type of every element in this
Listpublic Iterator iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in interface List
iterator
in interface Set
iterator
in class AbstractList
public Comparator comparator()
comparator
in interface SortedSet
public Object first()
first
in interface SortedSet
NoSuchElementException
- if the sorted set is emptypublic Object last()
last
in interface SortedSet
NoSuchElementException
- if the sorted set is emptypublic SortedSet headSet(Object toElement)
headSet
in interface SortedSet
toElement
- high endpoint (exclusive) of the headSetIllegalArgumentException
- if toElement is not found in
the SortedSetpublic SortedSet tailSet(Object fromElement)
tailSet
in interface SortedSet
fromElement
- the first element to include in the resulting setIllegalArgumentException
- if fromElement is not found
in the SortedSetpublic SortedSet subSet(Object fromElement, Object toElement)
subSet
in interface SortedSet
fromElement
- the first element to include in the resulting settoElement
- the first element following fromElement to
not include in the resulting setIllegalArgumentException
- if either fromElement or
toElement is not found in the SortedSetpublic Object clone()
public void readExternal(DataInput in) throws IOException
readExternal
in interface ExternalizableLite
in
- the DataInput stream to read data from in order to restore
the state of this objectIOException
- if an I/O exception occursNotActiveException
- if the object is not in its initial
state, and therefore cannot be deserialized intopublic void writeExternal(DataOutput out) throws IOException
writeExternal
in interface ExternalizableLite
out
- the DataOutput stream to write the state of this object toIOException
- if an I/O exception occurspublic int compareTo(Object o)
All elements contained in both Lists must implement the Comparable interface. This method will compare the corresponding list element left-to-right and will immediately return the first non-zero comparison result. (A null element is always considered to be "less than" any non-null element.)
If all corresponding elements are equal, this method will return a negative integer if the size of this List is less than the size of the specified List, a positive integer if the size of this List is greater, and zero if the Lists are equal.
compareTo
in interface Comparable
o
- the Object to be comparedClassCastException
- if the specified object does not implement
the List
interface, some elements of either list do
not implement the Comparable
interface, or if an
element object type prevents it from being compared to another
elementNullPointerException
- if the specified List itself or any of its
elements are nullpublic boolean equals(Object o)
equals
in interface Collection
equals
in interface List
equals
in interface Set
equals
in class AbstractList
o
- some other Object that is likely to be a Collection or some
more specific type (with its related overloaded definition of
what it thinks that equals() means)protected Map getValueIndex()