Colt 1.2.0

cern.colt.list
Class ObjectArrayList

java.lang.Object
  extended bycern.colt.PersistentObject
      extended bycern.colt.list.AbstractCollection
          extended bycern.colt.list.AbstractList
              extended bycern.colt.list.ObjectArrayList
All Implemented Interfaces:
Cloneable, Serializable

public class ObjectArrayList
extends AbstractList

Resizable list holding Object elements; implemented with arrays. First see the package summary and javadoc tree view to get the broad picture.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
 
Constructor Summary
ObjectArrayList()
          Constructs an empty list.
ObjectArrayList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
ObjectArrayList(Object[] elements)
          Constructs a list containing the specified elements.
 
Method Summary
 void add(Object element)
          Appends the specified element to the end of this list.
 void addAllOfFromTo(ObjectArrayList other, int from, int to)
          Appends the part of the specified list between from (inclusive) and to (inclusive) to the receiver.
 void beforeInsert(int index, Object element)
          Inserts the specified element before the specified position into the receiver.
 void beforeInsertAllOfFromTo(int index, ObjectArrayList other, int from, int to)
          Inserts the part of the specified list between otherFrom (inclusive) and otherTo (inclusive) before the specified position into the receiver.
 int binarySearch(Object key)
          Searches the receiver for the specified value using the binary search algorithm.
 int binarySearchFromTo(Object key, int from, int to)
          Searches the receiver for the specified value using the binary search algorithm.
 int binarySearchFromTo(Object key, int from, int to, Comparator comparator)
          Searches the receiver for the specified value using the binary search algorithm.
 Object clone()
          Returns a copy of the receiver such that the copy and the receiver share the same elements, but do not share the same array to index them; So modifying an object in the copy modifies the object in the receiver and vice versa; However, structurally modifying the copy (for example changing its size, setting other objects at indexes, etc.) does not affect the receiver and vice versa.
 boolean contains(Object elem, boolean testForEquality)
          Returns true if the receiver contains the specified element.
 ObjectArrayList copy()
          Returns a copy of the receiver; call clone() and casts the result.
 void delete(Object element, boolean testForEquality)
          Deletes the first element from the receiver that matches the specified element.
 Object[] elements()
          Returns the elements currently stored, including invalid elements between size and capacity, if any.
 ObjectArrayList elements(Object[] elements)
          Sets the receiver's elements to be the specified array (not a copy of it).
 void ensureCapacity(int minCapacity)
          Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
 boolean equals(Object otherObj)
          Compares the specified Object with the receiver for equality.
 boolean equals(Object otherObj, boolean testForEquality)
          Compares the specified Object with the receiver for equality.
 void fillFromToWith(int from, int to, Object val)
          Sets the specified range of elements in the specified array to the specified value.
 boolean forEach(ObjectProcedure procedure)
          Applies a procedure to each element of the receiver, if any.
 Object get(int index)
          Returns the element at the specified position in the receiver.
 Object getQuick(int index)
          Returns the element at the specified position in the receiver; WARNING: Does not check preconditions.
 int indexOf(Object element, boolean testForEquality)
          Returns the index of the first occurrence of the specified element.
 int indexOfFromTo(Object element, int from, int to, boolean testForEquality)
          Returns the index of the first occurrence of the specified element.
 boolean isSortedFromTo(int from, int to)
          Determines whether the receiver is sorted ascending, according to the natural ordering of its elements.
 int lastIndexOf(Object element, boolean testForEquality)
          Returns the index of the last occurrence of the specified element.
 int lastIndexOfFromTo(Object element, int from, int to, boolean testForEquality)
          Returns the index of the last occurrence of the specified element.
 void mergeSortFromTo(int from, int to)
          Sorts the specified range of the receiver into ascending order, according to the natural ordering of its elements.
 void mergeSortFromTo(int from, int to, Comparator c)
          Sorts the receiver according to the order induced by the specified comparator.
 ObjectArrayList partFromTo(int from, int to)
          Returns a new list of the part of the receiver between from, inclusive, and to, inclusive.
 void quickSortFromTo(int from, int to)
          Sorts the specified range of the receiver into ascending order, according to the natural ordering of its elements.
 void quickSortFromTo(int from, int to, Comparator c)
          Sorts the receiver according to the order induced by the specified comparator.
 boolean removeAll(ObjectArrayList other, boolean testForEquality)
          Removes from the receiver all elements that are contained in the specified list.
 void removeFromTo(int from, int to)
          Removes from the receiver all elements whose index is between from, inclusive and to, inclusive.
 void replaceFromToWithFrom(int from, int to, ObjectArrayList other, int otherFrom)
          Replaces a number of elements in the receiver with the same number of elements of another list.
 void replaceFromToWithFromTo(int from, int to, ObjectArrayList other, int otherFrom, int otherTo)
          Replaces the part between from (inclusive) and to (inclusive) with the other list's part between otherFrom and otherTo.
 void replaceFromWith(int from, Collection other)
          Replaces the part of the receiver starting at from (inclusive) with all the elements of the specified collection.
 boolean retainAll(ObjectArrayList other, boolean testForEquality)
          Retains (keeps) only the elements in the receiver that are contained in the specified other list.
 void reverse()
          Reverses the elements of the receiver.
 void set(int index, Object element)
          Replaces the element at the specified position in the receiver with the specified element.
 void setQuick(int index, Object element)
          Replaces the element at the specified position in the receiver with the specified element; WARNING: Does not check preconditions.
 void shuffleFromTo(int from, int to)
          Randomly permutes the part of the receiver between from (inclusive) and to (inclusive).
 int size()
          Returns the number of elements contained in the receiver.
 ObjectArrayList times(int times)
          Returns a list which is a concatenation of times times the receiver.
 Object[] toArray(Object[] array)
          Returns an array containing all of the elements in the receiver in the correct order.
 ArrayList toList()
          Returns a java.util.ArrayList containing all the elements in the receiver.
 String toString()
          Returns a string representation of the receiver, containing the String representation of each element.
 void trimToSize()
          Trims the capacity of the receiver to be the receiver's current size.
 
Methods inherited from class cern.colt.list.AbstractList
addAllOf, beforeInsertAllOf, clear, mergeSort, quickSort, remove, setSize, shuffle, sort, sortFromTo
 
Methods inherited from class cern.colt.list.AbstractCollection
isEmpty
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectArrayList

public ObjectArrayList()
Constructs an empty list.


ObjectArrayList

public ObjectArrayList(Object[] elements)
Constructs a list containing the specified elements. The initial size and capacity of the list is the length of the array. WARNING: For efficiency reasons and to keep memory usage low, the array is not copied. So if subsequently you modify the specified array directly via the [] operator, be sure you know what you're doing.

Parameters:
elements - the array to be backed by the the constructed list

ObjectArrayList

public ObjectArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
Method Detail

add

public void add(Object element)
Appends the specified element to the end of this list.

Parameters:
element - element to be appended to this list.

addAllOfFromTo

public void addAllOfFromTo(ObjectArrayList other,
                           int from,
                           int to)
Appends the part of the specified list between from (inclusive) and to (inclusive) to the receiver.

Parameters:
other - the list to be added to the receiver.
from - the index of the first element to be appended (inclusive).
to - the index of the last element to be appended (inclusive).
Throws:
IndexOutOfBoundsException - index is out of range (other.size()>0 && (from<0 || from>to || to>=other.size())).

beforeInsert

public void beforeInsert(int index,
                         Object element)
Inserts the specified element before the specified position into the receiver. Shifts the element currently at that position (if any) and any subsequent elements to the right.

Parameters:
index - index before which the specified element is to be inserted (must be in [0,size]).
element - element to be inserted.
Throws:
IndexOutOfBoundsException - index is out of range (index < 0 || index > size()).

beforeInsertAllOfFromTo

public void beforeInsertAllOfFromTo(int index,
                                    ObjectArrayList other,
                                    int from,
                                    int to)
Inserts the part of the specified list between otherFrom (inclusive) and otherTo (inclusive) before the specified position into the receiver. Shifts the element currently at that position (if any) and any subsequent elements to the right.

Parameters:
index - index before which to insert first element from the specified list (must be in [0,size])..
other - list of which a part is to be inserted into the receiver.
from - the index of the first element to be inserted (inclusive).
to - the index of the last element to be inserted (inclusive).
Throws:
IndexOutOfBoundsException - index is out of range (other.size()>0 && (from<0 || from>to || to>=other.size())).
IndexOutOfBoundsException - index is out of range (index < 0 || index > size()).

binarySearch

public int binarySearch(Object key)
Searches the receiver for the specified value using the binary search algorithm. The receiver must be sorted into ascending order according to the natural ordering of its elements (as by the sort method) prior to making this call. If it is not sorted, the results are undefined: in particular, the call may enter an infinite loop. If the receiver contains multiple elements equal to the specified object, there is no guarantee which instance will be found.

Parameters:
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the receiver; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the receiver: the index of the first element greater than the key, or receiver.size(), if all elements in the receiver are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Comparable, Arrays

binarySearchFromTo

public int binarySearchFromTo(Object key,
                              int from,
                              int to)
Searches the receiver for the specified value using the binary search algorithm. The receiver must be sorted into ascending order according to the natural ordering of its elements (as by the sort method) prior to making this call. If it is not sorted, the results are undefined: in particular, the call may enter an infinite loop. If the receiver contains multiple elements equal to the specified object, there is no guarantee which instance will be found.

Parameters:
key - the value to be searched for.
from - the leftmost search position, inclusive.
to - the rightmost search position, inclusive.
Returns:
index of the search key, if it is contained in the receiver; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the receiver: the index of the first element greater than the key, or receiver.size(), if all elements in the receiver are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Comparable, Arrays

binarySearchFromTo

public int binarySearchFromTo(Object key,
                              int from,
                              int to,
                              Comparator comparator)
Searches the receiver for the specified value using the binary search algorithm. The receiver must be sorted into ascending order according to the specified comparator. All elements in the range must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the range).

If the receiver is not sorted, the results are undefined: in particular, the call may enter an infinite loop. If the receiver contains multiple elements equal to the specified object, there is no guarantee which instance will be found.

Parameters:
key - the value to be searched for.
from - the leftmost search position, inclusive.
to - the rightmost search position, inclusive.
comparator - the comparator by which the receiver is sorted.
Returns:
index of the search key, if it is contained in the receiver; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the receiver: the index of the first element greater than the key, or receiver.size(), if all elements in the receiver are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
Throws:
ClassCastException - if the receiver contains elements that are not mutually comparable using the specified comparator.
See Also:
Sorting, Arrays, Comparator

clone

public Object clone()
Returns a copy of the receiver such that the copy and the receiver share the same elements, but do not share the same array to index them; So modifying an object in the copy modifies the object in the receiver and vice versa; However, structurally modifying the copy (for example changing its size, setting other objects at indexes, etc.) does not affect the receiver and vice versa.

Overrides:
clone in class PersistentObject
Returns:
a copy of the receiver.

contains

public boolean contains(Object elem,
                        boolean testForEquality)
Returns true if the receiver contains the specified element. Tests for equality or identity as specified by testForEquality.

Parameters:
testForEquality - if true -> test for equality, otherwise for identity.

copy

public ObjectArrayList copy()
Returns a copy of the receiver; call clone() and casts the result. Returns a copy such that the copy and the receiver share the same elements, but do not share the same array to index them; So modifying an object in the copy modifies the object in the receiver and vice versa; However, structurally modifying the copy (for example changing its size, setting other objects at indexes, etc.) does not affect the receiver and vice versa.

Returns:
a copy of the receiver.

delete

public void delete(Object element,
                   boolean testForEquality)
Deletes the first element from the receiver that matches the specified element. Does nothing, if no such matching element is contained. Tests elements for equality or identity as specified by testForEquality. When testing for equality, two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).)

Parameters:
testForEquality - if true -> tests for equality, otherwise for identity.
element - the element to be deleted.

elements

public Object[] elements()
Returns the elements currently stored, including invalid elements between size and capacity, if any. WARNING: For efficiency reasons and to keep memory usage low, the array is not copied. So if subsequently you modify the returned array directly via the [] operator, be sure you know what you're doing.

Returns:
the elements currently stored.

elements

public ObjectArrayList elements(Object[] elements)
Sets the receiver's elements to be the specified array (not a copy of it). The size and capacity of the list is the length of the array. WARNING: For efficiency reasons and to keep memory usage low, the array is not copied. So if subsequently you modify the specified array directly via the [] operator, be sure you know what you're doing.

Parameters:
elements - the new elements to be stored.
Returns:
the receiver itself.

ensureCapacity

public void ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver.

Parameters:
minCapacity - the desired minimum capacity.

equals

public boolean equals(Object otherObj)
Compares the specified Object with the receiver for equality. Returns true if and only if the specified Object is also an ObjectArrayList, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. In other words, two lists are defined to be equal if they contain the same elements in the same order. Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).)

Parameters:
otherObj - the Object to be compared for equality with the receiver.
Returns:
true if the specified Object is equal to the receiver.

equals

public boolean equals(Object otherObj,
                      boolean testForEquality)
Compares the specified Object with the receiver for equality. Returns true if and only if the specified Object is also an ObjectArrayList, both lists have the same size, and all corresponding pairs of elements in the two lists are the same. In other words, two lists are defined to be equal if they contain the same elements in the same order. Tests elements for equality or identity as specified by testForEquality. When testing for equality, two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).)

Parameters:
otherObj - the Object to be compared for equality with the receiver.
testForEquality - if true -> tests for equality, otherwise for identity.
Returns:
true if the specified Object is equal to the receiver.

fillFromToWith

public void fillFromToWith(int from,
                           int to,
                           Object val)
Sets the specified range of elements in the specified array to the specified value.

Parameters:
from - the index of the first element (inclusive) to be filled with the specified value.
to - the index of the last element (inclusive) to be filled with the specified value.
val - the value to be stored in the specified elements of the receiver.

forEach

public boolean forEach(ObjectProcedure procedure)
Applies a procedure to each element of the receiver, if any. Starts at index 0, moving rightwards.

Parameters:
procedure - the procedure to be applied. Stops iteration if the procedure returns false, otherwise continues.
Returns:
false if the procedure stopped before all elements where iterated over, true otherwise.

get

public Object get(int index)
Returns the element at the specified position in the receiver.

Parameters:
index - index of element to return.
Throws:
IndexOutOfBoundsException - index is out of range (index < 0 || index >= size()).

getQuick

public Object getQuick(int index)
Returns the element at the specified position in the receiver; WARNING: Does not check preconditions. Provided with invalid parameters this method may return invalid elements without throwing any exception! You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): index >= 0 && index < size().

Parameters:
index - index of element to return.

indexOf

public int indexOf(Object element,
                   boolean testForEquality)
Returns the index of the first occurrence of the specified element. Returns -1 if the receiver does not contain this element. Tests for equality or identity as specified by testForEquality.

Parameters:
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
the index of the first occurrence of the element in the receiver; returns -1 if the element is not found.

indexOfFromTo

public int indexOfFromTo(Object element,
                         int from,
                         int to,
                         boolean testForEquality)
Returns the index of the first occurrence of the specified element. Returns -1 if the receiver does not contain this element. Searches between from, inclusive and to, inclusive. Tests for equality or identity as specified by testForEquality.

Parameters:
element - element to search for.
from - the leftmost search position, inclusive.
to - the rightmost search position, inclusive.
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
the index of the first occurrence of the element in the receiver; returns -1 if the element is not found.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

isSortedFromTo

public boolean isSortedFromTo(int from,
                              int to)
Determines whether the receiver is sorted ascending, according to the natural ordering of its elements. All elements in this range must implement the Comparable interface. Furthermore, all elements in this range must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

Parameters:
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (inclusive) to be sorted.
Returns:
true if the receiver is sorted ascending, false otherwise.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

lastIndexOf

public int lastIndexOf(Object element,
                       boolean testForEquality)
Returns the index of the last occurrence of the specified element. Returns -1 if the receiver does not contain this element. Tests for equality or identity as specified by testForEquality.

Parameters:
element - the element to be searched for.
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
the index of the last occurrence of the element in the receiver; returns -1 if the element is not found.

lastIndexOfFromTo

public int lastIndexOfFromTo(Object element,
                             int from,
                             int to,
                             boolean testForEquality)
Returns the index of the last occurrence of the specified element. Returns -1 if the receiver does not contain this element. Searches beginning at to, inclusive until from, inclusive. Tests for equality or identity as specified by testForEquality.

Parameters:
element - element to search for.
from - the leftmost search position, inclusive.
to - the rightmost search position, inclusive.
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
the index of the last occurrence of the element in the receiver; returns -1 if the element is not found.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

mergeSortFromTo

public void mergeSortFromTo(int from,
                            int to)
Sorts the specified range of the receiver into ascending order, according to the natural ordering of its elements. All elements in this range must implement the Comparable interface. Furthermore, all elements in this range must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set. It is generally better to call sort() or sortFromTo(...) instead, because those methods automatically choose the best sorting algorithm.

Specified by:
mergeSortFromTo in class AbstractList
Parameters:
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (inclusive) to be sorted.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

mergeSortFromTo

public void mergeSortFromTo(int from,
                            int to,
                            Comparator c)
Sorts the receiver according to the order induced by the specified comparator. All elements in the range must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the range).

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

Parameters:
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (inclusive) to be sorted.
c - the comparator to determine the order of the receiver.
Throws:
ClassCastException - if the array contains elements that are not mutually comparable using the specified comparator.
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > a.length
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).
See Also:
Comparator

partFromTo

public ObjectArrayList partFromTo(int from,
                                  int to)
Returns a new list of the part of the receiver between from, inclusive, and to, inclusive.

Parameters:
from - the index of the first element (inclusive).
to - the index of the last element (inclusive).
Returns:
a new list
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

quickSortFromTo

public void quickSortFromTo(int from,
                            int to)
Sorts the specified range of the receiver into ascending order, according to the natural ordering of its elements. All elements in this range must implement the Comparable interface. Furthermore, all elements in this range must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set. It is generally better to call sort() or sortFromTo(...) instead, because those methods automatically choose the best sorting algorithm.

Specified by:
quickSortFromTo in class AbstractList
Parameters:
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (inclusive) to be sorted.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

quickSortFromTo

public void quickSortFromTo(int from,
                            int to,
                            Comparator c)
Sorts the receiver according to the order induced by the specified comparator. All elements in the range must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the range).

The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

Parameters:
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (inclusive) to be sorted.
c - the comparator to determine the order of the receiver.
Throws:
ClassCastException - if the array contains elements that are not mutually comparable using the specified comparator.
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > a.length
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).
See Also:
Comparator

removeAll

public boolean removeAll(ObjectArrayList other,
                         boolean testForEquality)
Removes from the receiver all elements that are contained in the specified list. Tests for equality or identity as specified by testForEquality.

Parameters:
other - the other list.
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
true if the receiver changed as a result of the call.

removeFromTo

public void removeFromTo(int from,
                         int to)
Removes from the receiver all elements whose index is between from, inclusive and to, inclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (to - from + 1) elements.

Specified by:
removeFromTo in class AbstractList
Parameters:
from - index of first element to be removed.
to - index of last element to be removed.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

replaceFromToWithFrom

public void replaceFromToWithFrom(int from,
                                  int to,
                                  ObjectArrayList other,
                                  int otherFrom)
Replaces a number of elements in the receiver with the same number of elements of another list. Replaces elements in the receiver, between from (inclusive) and to (inclusive), with elements of other, starting from otherFrom (inclusive).

Parameters:
from - the position of the first element to be replaced in the receiver
to - the position of the last element to be replaced in the receiver
other - list holding elements to be copied into the receiver.
otherFrom - position of first element within other list to be copied.

replaceFromToWithFromTo

public void replaceFromToWithFromTo(int from,
                                    int to,
                                    ObjectArrayList other,
                                    int otherFrom,
                                    int otherTo)
Replaces the part between from (inclusive) and to (inclusive) with the other list's part between otherFrom and otherTo. Powerful (and tricky) method! Both parts need not be of the same size (part A can both be smaller or larger than part B). Parts may overlap. Receiver and other list may (but most not) be identical. If from > to, then inserts other part before from.

Parameters:
from - the first element of the receiver (inclusive)
to - the last element of the receiver (inclusive)
other - the other list (may be identical with receiver)
otherFrom - the first element of the other list (inclusive)
otherTo - the last element of the other list (inclusive)

Examples:

 a=[0, 1, 2, 3, 4, 5, 6, 7]
 b=[50, 60, 70, 80, 90]
 a.R(...)=a.replaceFromToWithFromTo(...)

 a.R(3,5,b,0,4)-->[0, 1, 2, 50, 60, 70, 80, 90, 6, 7]
 a.R(1,6,b,0,4)-->[0, 50, 60, 70, 80, 90, 7]
 a.R(0,6,b,0,4)-->[50, 60, 70, 80, 90, 7]
 a.R(3,5,b,1,2)-->[0, 1, 2, 60, 70, 6, 7]
 a.R(1,6,b,1,2)-->[0, 60, 70, 7]
 a.R(0,6,b,1,2)-->[60, 70, 7]
 a.R(5,3,b,0,4)-->[0, 1, 2, 3, 4, 50, 60, 70, 80, 90, 5, 6, 7]
 a.R(5,0,b,0,4)-->[0, 1, 2, 3, 4, 50, 60, 70, 80, 90, 5, 6, 7]
 a.R(5,3,b,1,2)-->[0, 1, 2, 3, 4, 60, 70, 5, 6, 7]
 a.R(5,0,b,1,2)-->[0, 1, 2, 3, 4, 60, 70, 5, 6, 7]

 Extreme cases:
 a.R(5,3,b,0,0)-->[0, 1, 2, 3, 4, 50, 5, 6, 7]
 a.R(5,3,b,4,4)-->[0, 1, 2, 3, 4, 90, 5, 6, 7]
 a.R(3,5,a,0,1)-->[0, 1, 2, 0, 1, 6, 7]
 a.R(3,5,a,3,5)-->[0, 1, 2, 3, 4, 5, 6, 7]
 a.R(3,5,a,4,4)-->[0, 1, 2, 4, 6, 7]
 a.R(5,3,a,0,4)-->[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7]
 a.R(0,-1,b,0,4)-->[50, 60, 70, 80, 90, 0, 1, 2, 3, 4, 5, 6, 7]
 a.R(0,-1,a,0,4)-->[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7]
 a.R(8,0,a,0,4)-->[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4]
 

replaceFromWith

public void replaceFromWith(int from,
                            Collection other)
Replaces the part of the receiver starting at from (inclusive) with all the elements of the specified collection. Does not alter the size of the receiver. Replaces exactly Math.max(0,Math.min(size()-from, other.size())) elements.

Specified by:
replaceFromWith in class AbstractList
Parameters:
from - the index at which to copy the first element from the specified collection.
other - Collection to replace part of the receiver
Throws:
IndexOutOfBoundsException - index is out of range (index < 0 || index >= size()).

retainAll

public boolean retainAll(ObjectArrayList other,
                         boolean testForEquality)
Retains (keeps) only the elements in the receiver that are contained in the specified other list. In other words, removes from the receiver all of its elements that are not contained in the specified other list. Tests for equality or identity as specified by testForEquality.

Parameters:
other - the other list to test against.
testForEquality - if true -> test for equality, otherwise for identity.
Returns:
true if the receiver changed as a result of the call.

reverse

public void reverse()
Reverses the elements of the receiver. Last becomes first, second last becomes second first, and so on.

Specified by:
reverse in class AbstractList

set

public void set(int index,
                Object element)
Replaces the element at the specified position in the receiver with the specified element.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Throws:
IndexOutOfBoundsException - index is out of range (index < 0 || index >= size()).

setQuick

public void setQuick(int index,
                     Object element)
Replaces the element at the specified position in the receiver with the specified element; WARNING: Does not check preconditions. Provided with invalid parameters this method may access invalid indexes without throwing any exception! You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): index >= 0 && index < size().

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.

shuffleFromTo

public void shuffleFromTo(int from,
                          int to)
Randomly permutes the part of the receiver between from (inclusive) and to (inclusive).

Specified by:
shuffleFromTo in class AbstractList
Parameters:
from - the index of the first element (inclusive) to be permuted.
to - the index of the last element (inclusive) to be permuted.
Throws:
IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).

size

public int size()
Returns the number of elements contained in the receiver.

Specified by:
size in class AbstractCollection

times

public ObjectArrayList times(int times)
Returns a list which is a concatenation of times times the receiver.

Parameters:
times - the number of times the receiver shall be copied.

toArray

public Object[] toArray(Object[] array)
Returns an array containing all of the elements in the receiver in the correct order. The runtime type of the returned array is that of the specified array. If the receiver fits 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 the receiver.

If the receiver fits in the specified array with room to spare (i.e., the array has more elements than the receiver), the element in the array immediately following the end of the receiver is set to null. This is useful in determining the length of the receiver only if the caller knows that the receiver does not contain any null elements.

Parameters:
array - the array into which the elements of the receiver are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the receiver.
Throws:
ArrayStoreException - the runtime type of array is not a supertype of the runtime type of every element in the receiver.

toList

public ArrayList toList()
Returns a java.util.ArrayList containing all the elements in the receiver.

Specified by:
toList in class AbstractCollection

toString

public String toString()
Returns a string representation of the receiver, containing the String representation of each element.

Overrides:
toString in class AbstractCollection

trimToSize

public void trimToSize()
Trims the capacity of the receiver to be the receiver's current size. Releases any superfluos internal memory. An application can use this operation to minimize the storage of the receiver.

Overrides:
trimToSize in class AbstractList

Colt 1.2.0

Jump to the Colt Homepage