Class ImmutableMultiList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- com.tangosol.util.ImmutableMultiList
-
- All Implemented Interfaces:
Iterable
,Collection
,List
,Set
public class ImmutableMultiList extends AbstractList implements List, Set
Implementation of the List interface in a read-only fashion based on a collection of arrays.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()
methods should be used.- Author:
- gg, mf 2009.1.20
- See Also:
ImmutableArrayList
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ImmutableMultiList.ListView
ListView exposes the underlying ImmutableMultiList through theList
interface, maintaining correct equals() and hashCode() semanticsprotected class
ImmutableMultiList.MultiIterator
ListIterator implementation based on the ImmutableMultiList.protected class
ImmutableMultiList.SetView
SetView exposes the underlying ImmutableMultiList through theSet
interface, maintaining correct equals() and hashCode() semantics
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ImmutableMultiList(Object[][] aao)
Construct a List containing the elements of the specified array of Object arrays.ImmutableMultiList(Collection collection)
Construct a List containing the elements of the specified Collection of Object arrays.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
calculateTotalLength(Object[][] aao)
Calculate the total number of element in the array of arrays.boolean
contains(Object o)
Returns true if this List contains the specified element.boolean
equals(Object o)
Compare this Collection / List / Set with some other Object and determine if the caller would believe this Object to equal that other Object.static Object[]
flatten(Object[][] aaoFrom, int cTotal, Object[] aoTo)
Create a single dimensional array containing all elements of the specified array of arrays.Object
get(int i)
Returns the element at the specified position in this List.List
getList()
Return a java.util.List view of this ImmutableMultiList.Set
getSet()
Return a java.util.Set view of this ImmutableMultiList.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.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.ListIterator
listIterator()
ListIterator
listIterator(int i)
int
size()
Returns the number of elements in this List.Spliterator
spliterator()
List
subList(int iFrom, int iTo)
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.-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, hashCode, remove, removeRange, set
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Constructor Detail
-
ImmutableMultiList
public ImmutableMultiList(Object[][] aao)
Construct a List containing the elements of the specified array of Object arrays.- Parameters:
aao
- the array of arrays backing the MultiList
-
ImmutableMultiList
public ImmutableMultiList(Collection collection)
Construct a List containing the elements of the specified Collection of Object arrays.- Parameters:
collection
- the Collection of arrays to fill this MultiList from
-
-
Method Detail
-
getList
public List getList()
Return a java.util.List view of this ImmutableMultiList.- Returns:
- a List view of this ImmutableMultiList
-
getSet
public Set getSet()
Return a java.util.Set view of this ImmutableMultiList.Note: this method does not ensure that the underlying ImmutableMultiList 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 SortedSet.
- Returns:
- a Set view of this ImmutableMultiList
-
spliterator
public Spliterator spliterator()
- Specified by:
spliterator
in interfaceCollection
- Specified by:
spliterator
in interfaceIterable
- Specified by:
spliterator
in interfaceList
- Specified by:
spliterator
in interfaceSet
-
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, a new array is allocated with the runtime type of the specified array and the size of this List.If the elements of the MultiList fit in the specified array with room to spare (i.e., the array has more elements than the MultuList), the element in the array immediately following the end of the last element is set to null.
- 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 MultiList 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 all the elements of the MultiList
- Throws:
ArrayStoreException
- if the runtime type of the specified array is not ao supertype of the runtime type of every element in this MultiList
-
listIterator
public ListIterator listIterator()
- Specified by:
listIterator
in interfaceList
- Overrides:
listIterator
in classAbstractList
-
listIterator
public ListIterator listIterator(int i)
- Specified by:
listIterator
in interfaceList
- Overrides:
listIterator
in classAbstractList
-
subList
public List subList(int iFrom, int iTo)
- Specified by:
subList
in interfaceList
- Overrides:
subList
in classAbstractList
-
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.
-
equals
public boolean equals(Object o)
Compare this Collection / List / Set 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
-
calculateTotalLength
public static int calculateTotalLength(Object[][] aao)
Calculate the total number of element in the array of arrays.- Parameters:
aao
- an array of arrays- Returns:
- the total number of elements
-
flatten
public static Object[] flatten(Object[][] aaoFrom, int cTotal, Object[] aoTo)
Create a single dimensional array containing all elements of the specified array of arrays.- Parameters:
aaoFrom
- an array of arrays to copy fromcTotal
- the total length of the flattened array; pass -1 for it to be calculatedaoTo
- an array to copy the elements into (optional)- Returns:
- an array containing all the elements of the array of arrays
- Throws:
ArrayIndexOutOfBoundsException
- if the total length parameter was not sufficient to hold the flattened array
-
-