Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.util
Class ImmutableMultiList

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by com.tangosol.util.ImmutableMultiList

All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List, java.util.Set

public class ImmutableMultiList
extends java.util.AbstractList
implements java.util.List, java.util.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
protected  class ImmutableMultiList.ListView
          ListView exposes the underlying ImmutableMultiList through the List interface, maintaining correct equals() and hashCode() semantics
protected  class ImmutableMultiList.MultiIterator
          ListIterator implementation based on the ImmutableMultiList.
protected  class ImmutableMultiList.SetView
          SetView exposes the underlying ImmutableMultiList through the Set interface, maintaining correct equals() and hashCode() semantics

 

Field Summary

 

Fields inherited from class java.util.AbstractList
modCount

 

Constructor Summary
ImmutableMultiList(java.util.Collection collection)
          Construct a List containing the elements of the specified Collection of Object arrays.
ImmutableMultiList(java.lang.Object[][] aao)
          Construct a List containing the elements of the specified array of Object arrays.

 

Method Summary
static int calculateTotalLength(java.lang.Object[][] aao)
          Calculate the total number of element in the array of arrays.
 boolean contains(java.lang.Object o)
          Returns true if this List contains the specified element.
 boolean equals(java.lang.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 java.lang.Object[] flatten(java.lang.Object[][] aaoFrom, int cTotal, java.lang.Object[] aoTo)
          Create a single dimensional array containing all elements of the specified array of arrays.
 java.lang.Object get(int i)
          Returns the element at the specified position in this List.
 java.util.List getList()
          Return a java.util.List view of this ImmutableMultiList.
 java.util.Set getSet()
          Return a java.util.Set view of this ImmutableMultiList.
 int indexOf(java.lang.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.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this list in proper sequence.
 int lastIndexOf(java.lang.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.
 java.util.ListIterator listIterator()
          Returns an iterator of the elements in this list (in proper sequence).
 java.util.ListIterator listIterator(int i)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list.
 int size()
          Returns the number of elements in this List.
 java.util.List subList(int iFrom, int iTo)
          Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this List in the order that the elements occur in the List.
 java.lang.Object[] toArray(java.lang.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 interface java.util.List
add, add, addAll, addAll, clear, containsAll, hashCode, isEmpty, remove, remove, removeAll, retainAll, set

 

Methods inherited from interface java.util.Set
add, addAll, clear, containsAll, hashCode, isEmpty, remove, removeAll, retainAll

 

Constructor Detail

ImmutableMultiList

public ImmutableMultiList(java.lang.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(java.util.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 java.util.List getList()
Return a java.util.List view of this ImmutableMultiList.
Returns:
a List view of this ImmutableMultiList

getSet

public java.util.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

size

public int size()
Returns the number of elements in this List.
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection
Returns:
the number of elements in this List

get

public java.lang.Object get(int i)
Returns the element at the specified position in this List.
Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList
Parameters:
i - the index of the element to return
Returns:
the element at the specified position in this List
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).

indexOf

public int indexOf(java.lang.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 interface java.util.List
Overrides:
indexOf in class java.util.AbstractList
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(java.lang.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 interface java.util.List
Overrides:
lastIndexOf in class java.util.AbstractList
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(java.lang.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 interface java.util.Collection
Specified by:
contains in interface java.util.List
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection
Parameters:
o - element whose presence in this List is to be tested
Returns:
true if this List contains the specified element

toArray

public java.lang.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 interface java.util.Collection
Specified by:
toArray in interface java.util.List
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
Returns:
an array containing all of the elements in this List
See Also:
Arrays.asList(Object[])

toArray

public java.lang.Object[] toArray(java.lang.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 interface java.util.Collection
Specified by:
toArray in interface java.util.List
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
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:
java.lang.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 java.util.ListIterator listIterator()
Returns an iterator of the elements in this list (in proper sequence). This implementation returns listIterator(0).
Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class java.util.AbstractList
Returns:
an iterator of the elements in this list (in proper sequence).
See Also:
AbstractList.listIterator(int)

listIterator

public java.util.ListIterator listIterator(int i)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to the next method. An initial call to the previous method would return the element with the specified index minus one.

This implementation returns a straightforward implementation of the ListIterator interface that extends the implementation of the Iterator interface returned by the iterator() method. The ListIterator implementation relies on the backing list's get(int), set(int, Object), add(int, Object) and remove(int) methods.

Note that the list iterator returned by this implementation will throw an UnsupportedOperationException in response to its remove, set and add methods unless the list's remove(int), set(int, Object), and add(int, Object) methods are overridden.

This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.

Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class java.util.AbstractList
Parameters:
i - index of the first element to be returned from the list iterator (by a call to the next method).
Returns:
a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list.
See Also:
AbstractList.modCount

subList

public java.util.List subList(int iFrom,
                              int iTo)
Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by operating on a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

     list.subList(from, to).clear();
 
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of the list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

This implementation returns a list that subclasses AbstractList. The subclass stores, in private fields, the offset of the subList within the backing list, the size of the subList (which can change over its lifetime), and the expected modCount value of the backing list. There are two variants of the subclass, one of which implements RandomAccess. If this list implements RandomAccess the returned list will be an instance of the subclass that implements RandomAccess.

The subclass's set(int, Object), get(int), add(int, Object), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corresponding methods on the backing abstract list, after bounds-checking the index and adjusting for the offset. The addAll(Collection c) method merely returns addAll(size, c).

The listIterator(int) method returns a "wrapper object" over a list iterator on the backing list, which is created with the corresponding method on the backing list. The iterator method merely returns listIterator(), and the size method merely returns the subclass's size field.

All methods first check to see if the actual modCount of the backing list is equal to its expected value, and throw a ConcurrentModificationException if it is not.

Specified by:
subList in interface java.util.List
Overrides:
subList in class java.util.AbstractList
Parameters:
iFrom - low endpoint (inclusive) of the subList.
iTo - high endpoint (exclusive) of the subList.
Returns:
a view of the specified range within this list.

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Specified by:
iterator in interface java.util.Set
Overrides:
iterator in class java.util.AbstractList
Returns:
an iterator over the elements in this list in proper sequence.
See Also:
AbstractList.modCount

equals

public boolean equals(java.lang.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 interface java.util.Collection
Specified by:
equals in interface java.util.List
Specified by:
equals in interface java.util.Set
Overrides:
equals in class java.util.AbstractList
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
See Also:
Object.equals(Object), Set.equals(Object), List.equals(Object)

calculateTotalLength

public static int calculateTotalLength(java.lang.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 java.lang.Object[] flatten(java.lang.Object[][] aaoFrom,
                                         int cTotal,
                                         java.lang.Object[] aoTo)
Create a single dimensional array containing all elements of the specified array of arrays.
Parameters:
aaoFrom - an array of arrays to copy from
cTotal - the total length of the flattened array; pass -1 for it to be calculated
aoTo - an array to copy the elements into (optional)
Returns:
an array containing all the elements of the array of arrays
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the total length parameter was not sufficient to hold the flattened array

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.