Class ImmutableArrayList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- com.tangosol.util.ImmutableArrayList
-
- All Implemented Interfaces:
ExternalizableLite
,Serializable
,Cloneable
,Comparable
,Iterable
,Collection
,List
,Set
,SortedSet
public class ImmutableArrayList extends AbstractList implements Collection, List, Set, SortedSet, Comparable, Cloneable, ExternalizableLite
Implementation of the Collection Framework interface "List" in a read- only fashion on top of an array data structure.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()
, andgetSortedSet()
methods should be used.- Author:
- cp 2001.10.09
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ImmutableArrayList.ListView
ListView exposes the underlying ImmutableArrayList through theList
interface, maintaining correct equals() and hashCode() semanticsprotected class
ImmutableArrayList.SetView
SetView exposes the underlying ImmutableArrayList through theSet
interface, maintaining correct equals() and hashCode() semanticsprotected class
ImmutableArrayList.SortedSetView
SetView exposes the underlying ImmutableArrayList through theSortedSet
interface, maintaining correct equals() and hashCode() semantics
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ImmutableArrayList()
Default constructor (necessary for the ExternalizableLite interface).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.ImmutableArrayList(Collection collection)
Construct a List containing the elements of the specified Collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, hashCode, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, containsAll, hashCode, isEmpty, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, subList
-
-
-
-
Constructor Detail
-
ImmutableArrayList
public ImmutableArrayList(Object[] ao, int of, int c)
Construct a List from a specified number of items in an array starting at the specified offset.- Parameters:
ao
- a non-null array of Objectsof
- an offset of the first item in the arrayc
- the number of items to use
-
ImmutableArrayList
public ImmutableArrayList(Object[] ao)
Construct a List from an array.- Parameters:
ao
- a non-null array of Objects
-
ImmutableArrayList
public ImmutableArrayList(Collection collection)
Construct a List containing the elements of the specified Collection.- Parameters:
collection
- the Collection to fill this List from
-
ImmutableArrayList
public ImmutableArrayList()
Default constructor (necessary for the ExternalizableLite interface).
-
-
Method Detail
-
getList
public List getList()
Return a java.util.List view of this ImmutableArrayList.- Returns:
- a List view of this ImmutableArrayList
-
getSet
public Set getSet()
Return a java.util.Set view of this ImmutableArrayList.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.
- Returns:
- a Set view of this ImmutableArrayList
-
getSortedSet
public SortedSet getSortedSet()
Return a java.util.SortedSet view of this ImmutableArrayList.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.
- Returns:
- a SortedSet view of this ImmutableArrayList
-
spliterator
public Spliterator spliterator()
- Specified by:
spliterator
in interfaceCollection
- Specified by:
spliterator
in interfaceIterable
- Specified by:
spliterator
in interfaceList
- Specified by:
spliterator
in interfaceSet
- Specified by:
spliterator
in interfaceSortedSet
-
size
public int size()
Returns the number of elements in this List.- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- Specified by:
size
in interfaceSet
- Specified by:
size
in classAbstractCollection
- Returns:
- the number of elements in this List
-
get
public Object get(int i)
Returns the element at the specified position in this List.- Specified by:
get
in interfaceList
- Specified by:
get
in classAbstractList
- Parameters:
i
- the index of the element to return- Returns:
- the element at the specified position in this List
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()).
-
indexOf
public 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. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
indexOf
in interfaceList
- Overrides:
indexOf
in classAbstractList
- Parameters:
o
- element to search for.- Returns:
- the index in this List of the first occurrence of the specified element, or -1 if this List does not contain this element.
-
lastIndexOf
public 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. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
lastIndexOf
in interfaceList
- Overrides:
lastIndexOf
in classAbstractList
- Parameters:
o
- element to search for.- Returns:
- the index in this List of the last occurrence of the specified element, or -1 if this List does not contain this element.
-
contains
public boolean contains(Object o)
Returns true if this List contains the specified element. More formally, returns true if and only if this List contains at least one element e such that (o==null ? e==null : o.equals(e)).- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceList
- Specified by:
contains
in interfaceSet
- Overrides:
contains
in classAbstractCollection
- Parameters:
o
- element whose presence in this List is to be tested- Returns:
- true if this List contains the specified element
-
toArray
public Object[] toArray()
Returns an array containing all of the elements in this List in the order that the elements occur in the List. The returned array will be "safe" in that no references to it are maintained by the List. The caller is thus free to modify the returned array.- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceList
- Specified by:
toArray
in interfaceSet
- Overrides:
toArray
in classAbstractCollection
- Returns:
- an array containing all of the elements in this List
-
toArray
public 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. If the elements all fit in the specified array, it is returned therein. Otherwise, ao new array is allocated with the runtime type of the specified array and the size of this List.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.)
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceList
- Specified by:
toArray
in interfaceSet
- Overrides:
toArray
in classAbstractCollection
- Parameters:
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 purpose- Returns:
- an array containing the elements of the List
- Throws:
ArrayStoreException
- if the runtime type of the specified array is not ao supertype of the runtime type of every element in this List
-
iterator
public Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Specified by:
iterator
in interfaceList
- Specified by:
iterator
in interfaceSet
- Overrides:
iterator
in classAbstractList
- Returns:
- an iterator over the elements in this list in proper sequence.
-
comparator
public Comparator comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.- Specified by:
comparator
in interfaceSortedSet
- Returns:
- the comparator associated with this sorted set, or null if it uses its elements' natural ordering
-
first
public Object first()
Returns the first element currently in this sorted set.- Specified by:
first
in interfaceSortedSet
- Returns:
- the first element currently in this sorted set
- Throws:
NoSuchElementException
- if the sorted set is empty
-
last
public Object last()
Returns the last element currently in this sorted set.- Specified by:
last
in interfaceSortedSet
- Returns:
- the last element currently in this sorted set
- Throws:
NoSuchElementException
- if the sorted set is empty
-
headSet
public 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.- Specified by:
headSet
in interfaceSortedSet
- Parameters:
toElement
- high endpoint (exclusive) of the headSet- Returns:
- a view of the specified initial range of this sorted set
- Throws:
IllegalArgumentException
- if toElement is not found in the SortedSet
-
tailSet
public 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.- Specified by:
tailSet
in interfaceSortedSet
- Parameters:
fromElement
- the first element to include in the resulting set- Returns:
- a view of the specified final range of this sorted set
- Throws:
IllegalArgumentException
- if fromElement is not found in the SortedSet
-
subSet
public 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.- Specified by:
subSet
in interfaceSortedSet
- Parameters:
fromElement
- the first element to include in the resulting settoElement
- the first element following fromElement to not include in the resulting set- Returns:
- a view of the specified range of this sorted set
- Throws:
IllegalArgumentException
- if either fromElement or toElement is not found in the SortedSet
-
clone
public Object clone()
Create a clone of the ImmutableArrayList.
-
readExternal
public void readExternal(DataInput in) throws IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- Parameters:
in
- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException
- if an I/O exception occursNotActiveException
- if the object is not in its initial state, and therefore cannot be deserialized into
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
compareTo
public int compareTo(Object o)
Compare this ImmutableArrayList with the passed Object to determine order.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.
- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the Object to be compared- Returns:
- a negative integer, zero, or a positive integer as this List evaluates to less than, equal to, or greater than the specified List object
- Throws:
ClassCastException
- if the specified object does not implement theList
interface, some elements of either list do not implement theComparable
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 null- Since:
- Coherence 3.2
-
equals
public 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.- Specified by:
equals
in interfaceCollection
- Specified by:
equals
in interfaceList
- Specified by:
equals
in interfaceSet
- Overrides:
equals
in classAbstractList
- Parameters:
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)- Returns:
- true iff this Object believes that it can make a defensible case that this Object is equal to the passed Object
-
getValueIndex
protected Map getValueIndex()
Create a reverse index from value to position if this List is big enough to warrant it.- Returns:
- a Map that is keyed by the values in this List, with a corresponding Map value being the index within this List that the value is located
-
-