Oracle® Coherence Java API Reference
v3.5.3

E15583-01

com.tangosol.util
Class ImmutableArrayList

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by com.tangosol.util.ImmutableArrayList
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.Set, java.util.SortedSet

public class ImmutableArrayList
extends java.util.AbstractList
implements java.util.Collection, java.util.List, java.util.Set, java.util.SortedSet, java.lang.Comparable, java.lang.Cloneable

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.

Author:
cp 2001.10.09

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ImmutableArrayList()
          Default constructor (necessary for the ExternalizableLite interface).
ImmutableArrayList(java.util.Collection collection)
          Construct a List containing the elements of the specified Collection.
ImmutableArrayList(java.lang.Object[] ao)
          Construct a List from an array.
ImmutableArrayList(java.lang.Object[] ao, int of, int c)
          Construct a List from a specified number of items in an array starting at the specified offset.
 
Method Summary
 java.lang.Object clone()
          Create a clone of the ImmutableArrayList.
 java.util.Comparator comparator()
          Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
 int compareTo(java.lang.Object o)
          Compare this ImmutableArrayList with the passed Object to determine order.
 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 / SortedSet with some other Object and determine if the caller would believe this Object to equal that other Object.
 java.lang.Object first()
          Returns the first element currently in this sorted set.
 java.lang.Object get(int i)
          Returns the element at the specified position in this List.
protected  java.util.Map getValueIndex()
          Create a reverse index from value to position if this List is big enough to warrant it.
 java.util.SortedSet headSet(java.lang.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(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.
 java.lang.Object last()
          Returns the last element currently in this sorted set.
 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.
 void readExternal(java.io.DataInput in)
          
 int size()
          Returns the number of elements in this List.
 java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.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.
 java.util.SortedSet tailSet(java.lang.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.
 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.
 void writeExternal(java.io.DataOutput out)
          
 
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 interface java.util.List
add, add, addAll, addAll, clear, containsAll, hashCode, isEmpty, listIterator, listIterator, remove, remove, removeAll, retainAll, set, subList
 

Constructor Detail

ImmutableArrayList

public ImmutableArrayList(java.lang.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 Objects
of - an offset of the first item in the array
c - the number of items to use

ImmutableArrayList

public ImmutableArrayList(java.lang.Object[] ao)
Construct a List from an array.

Parameters:
ao - a non-null array of Objects

ImmutableArrayList

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

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

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, 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 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 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:
java.lang.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 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.

comparator

public java.util.Comparator comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

Specified by:
comparator in interface java.util.SortedSet
Returns:
the comparator associated with this sorted set, or null if it uses its elements' natural ordering

first

public java.lang.Object first()
Returns the first element currently in this sorted set.

Specified by:
first in interface java.util.SortedSet
Returns:
the first element currently in this sorted set
Throws:
java.util.NoSuchElementException - if the sorted set is empty

last

public java.lang.Object last()
Returns the last element currently in this sorted set.

Specified by:
last in interface java.util.SortedSet
Returns:
the last element currently in this sorted set
Throws:
java.util.NoSuchElementException - if the sorted set is empty

headSet

public java.util.SortedSet headSet(java.lang.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 interface java.util.SortedSet
Parameters:
toElement - high endpoint (exclusive) of the headSet
Returns:
a view of the specified initial range of this sorted set
Throws:
java.lang.IllegalArgumentException - if toElement is not found in the SortedSet

tailSet

public java.util.SortedSet tailSet(java.lang.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 interface java.util.SortedSet
Parameters:
fromElement - the first element to include in the resulting set
Returns:
a view of the specified final range of this sorted set
Throws:
java.lang.IllegalArgumentException - if fromElement is not found in the SortedSet

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.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 interface java.util.SortedSet
Parameters:
fromElement - the first element to include in the resulting set
toElement - the first element following fromElement to not include in the resulting set
Returns:
a view of the specified range of this sorted set
Throws:
java.lang.IllegalArgumentException - if either fromElement or toElement is not found in the SortedSet

clone

public java.lang.Object clone()
Create a clone of the ImmutableArrayList.

Returns:
a clone of this list

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException

Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException

Throws:
java.io.IOException

compareTo

public int compareTo(java.lang.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 interface java.lang.Comparable
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:
java.lang.ClassCastException - 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 element
java.lang.NullPointerException - if the specified List itself or any of its elements are null
Since:
Coherence 3.2

equals

public boolean equals(java.lang.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 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

getValueIndex

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

Oracle® Coherence Java API Reference
v3.5.3

E15583-01

Copyright © 2000, 2010, Oracle. All rights reserved.