Package cern.colt.list
Class ByteArrayList
java.lang.Object
cern.colt.PersistentObject
cern.colt.list.AbstractCollection
cern.colt.list.AbstractList
cern.colt.list.AbstractByteList
cern.colt.list.ByteArrayList
- All Implemented Interfaces:
Serializable,Cloneable
Resizable list holding
byte elements; implemented with arrays.
First see the package summary and javadoc
tree view to get the broad picture.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]The array buffer into which the elements of the list are stored.Fields inherited from class cern.colt.list.AbstractByteList
size -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty list.ByteArrayList(byte[] elements) Constructs a list containing the specified elements.ByteArrayList(int initialCapacity) Constructs an empty list with the specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(byte element) Appends the specified element to the end of this list.voidbeforeInsert(int index, byte element) Inserts the specified element before the specified position into the receiver.intbinarySearchFromTo(byte key, int from, int to) Searches the receiver for the specified value using the binary search algorithm.clone()Returns a deep copy of the receiver.copy()Returns a deep copy of the receiver; usesclone()and casts the result.voidcountSortFromTo(int from, int to) Sorts the specified range of the receiver into ascending numerical order.protected voidcountSortFromTo(int from, int to, byte min, byte max) Sorts the specified range of the receiver into ascending numerical order.byte[]elements()Returns the elements currently stored, including invalid elements between size and capacity, if any.elements(byte[] elements) Sets the receiver's elements to be the specified array (not a copy of it).voidensureCapacity(int minCapacity) Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.booleanCompares the specified Object with the receiver.booleanforEach(ByteProcedure procedure) Applies a procedure to each element of the receiver, if any.byteget(int index) Returns the element at the specified position in the receiver.bytegetQuick(int index) Returns the element at the specified position in the receiver; WARNING: Does not check preconditions.intindexOfFromTo(byte element, int from, int to) Returns the index of the first occurrence of the specified element.intlastIndexOfFromTo(byte element, int from, int to) Returns the index of the last occurrence of the specified element.partFromTo(int from, int to) Returns a new list of the part of the receiver betweenfrom, inclusive, andto, inclusive.booleanremoveAll(AbstractByteList other) Removes from the receiver all elements that are contained in the specified list.voidreplaceFromToWithFrom(int from, int to, AbstractByteList other, int otherFrom) Replaces a number of elements in the receiver with the same number of elements of another list.booleanretainAll(AbstractByteList other) Retains (keeps) only the elements in the receiver that are contained in the specified other list.voidreverse()Reverses the elements of the receiver.voidset(int index, byte element) Replaces the element at the specified position in the receiver with the specified element.voidsetQuick(int index, byte element) Replaces the element at the specified position in the receiver with the specified element; WARNING: Does not check preconditions.voidshuffleFromTo(int from, int to) Randomly permutes the part of the receiver betweenfrom(inclusive) andto(inclusive).voidsortFromTo(int from, int to) Sorts the specified range of the receiver into ascending order.voidTrims the capacity of the receiver to be the receiver's current size.Methods inherited from class cern.colt.list.AbstractByteList
addAllOfFromTo, beforeInsertAllOfFromTo, beforeInsertDummies, binarySearch, contains, delete, fillFromToWith, indexOf, lastIndexOf, mergeSortFromTo, mergeSortFromTo, quickSortFromTo, quickSortFromTo, removeFromTo, replaceFromToWithFromTo, replaceFromWith, setSizeRaw, size, times, toList, toStringMethods inherited from class cern.colt.list.AbstractList
addAllOf, beforeInsertAllOf, checkRange, checkRangeFromTo, clear, mergeSort, quickSort, remove, setSize, shuffle, sortMethods inherited from class cern.colt.list.AbstractCollection
isEmpty
-
Field Details
-
elements
protected byte[] elementsThe array buffer into which the elements of the list are stored. The capacity of the list is the length of this array buffer.
-
-
Constructor Details
-
ByteArrayList
public ByteArrayList()Constructs an empty list. -
ByteArrayList
public ByteArrayList(byte[] 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
-
ByteArrayList
public ByteArrayList(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 Details
-
add
public void add(byte element) Appends the specified element to the end of this list.- Overrides:
addin classAbstractByteList- Parameters:
element- element to be appended to this list.
-
beforeInsert
public void beforeInsert(int index, byte 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.- Overrides:
beforeInsertin classAbstractByteList- 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()).
-
binarySearchFromTo
public int binarySearchFromTo(byte key, int from, int to) Searches the receiver for the specified value using the binary search algorithm. The receiver must must be sorted (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.- Overrides:
binarySearchFromToin classAbstractByteList- 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, orreceiver.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:
-
clone
Returns a deep copy of the receiver.- Overrides:
clonein classAbstractByteList- Returns:
- a deep copy of the receiver.
-
copy
Returns a deep copy of the receiver; usesclone()and casts the result.- Returns:
- a deep copy of the receiver.
-
countSortFromTo
public void countSortFromTo(int from, int to) Sorts the specified range of the receiver into ascending numerical order. The sorting algorithm is a count sort. This algorithm offers guaranteed O(Max(n,256)) performance.- Parameters:
from- the index of the first element (inclusive) to be sorted.to- the index of the last element (inclusive) to be sorted.
-
countSortFromTo
protected void countSortFromTo(int from, int to, byte min, byte max) Sorts the specified range of the receiver into ascending numerical order. The sorting algorithm is a count sort. This algorithm offers guaranteed- Performance: O(Max(n,max-min+1)).
- Space requirements: int[max-min+1] buffer.
This algorithm is only applicable if max-min+1 is not large! But if applicable, it usually outperforms quicksort by a factor of 3-4.
- Parameters:
from- the index of the first element (inclusive) to be sorted.to- the index of the last element (inclusive) to be sorted.min- the smallest element contained in the range.max- the largest element contained in the range.
-
elements
public byte[] 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.- Overrides:
elementsin classAbstractByteList- Returns:
- the elements currently stored.
-
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.- Overrides:
elementsin classAbstractByteList- 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.- Specified by:
ensureCapacityin classAbstractByteList- Parameters:
minCapacity- the desired minimum capacity.
-
equals
Compares the specified Object with the receiver. Returns true if and only if the specified Object is also an ArrayList of the same type, both Lists have the same size, and all corresponding pairs of elements in the two Lists are identical. In other words, two Lists are defined to be equal if they contain the same elements in the same order.- Overrides:
equalsin classAbstractByteList- Parameters:
otherObj- the Object to be compared for equality with the receiver.- Returns:
- true if the specified Object is equal to the receiver.
-
forEach
Applies a procedure to each element of the receiver, if any. Starts at index 0, moving rightwards.- Overrides:
forEachin classAbstractByteList- Parameters:
procedure- the procedure to be applied. Stops iteration if the procedure returnsfalse, otherwise continues.- Returns:
falseif the procedure stopped before all elements where iterated over,trueotherwise.
-
get
public byte get(int index) Returns the element at the specified position in the receiver.- Overrides:
getin classAbstractByteList- Parameters:
index- index of element to return.- Throws:
IndexOutOfBoundsException- index is out of range (index < 0 || index >= size()).
-
getQuick
public byte 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().- Specified by:
getQuickin classAbstractByteList- Parameters:
index- index of element to return.
-
indexOfFromTo
public int indexOfFromTo(byte element, int from, int to) Returns the index of the first occurrence of the specified element. Returns-1if the receiver does not contain this element. Searches betweenfrom, inclusive andto, inclusive. Tests for identity.- Overrides:
indexOfFromToin classAbstractByteList- Parameters:
element- element to search for.from- the leftmost search position, inclusive.to- the rightmost search position, inclusive.- Returns:
- the index of the first occurrence of the element in the receiver;
returns
-1if the element is not found. - Throws:
IndexOutOfBoundsException- index is out of range (size()>0 && (from<0 || from>to || to>=size())).
-
lastIndexOfFromTo
public int lastIndexOfFromTo(byte element, int from, int to) Returns the index of the last occurrence of the specified element. Returns-1if the receiver does not contain this element. Searches beginning atto, inclusive untilfrom, inclusive. Tests for identity.- Overrides:
lastIndexOfFromToin classAbstractByteList- Parameters:
element- element to search for.from- the leftmost search position, inclusive.to- the rightmost search position, inclusive.- Returns:
- the index of the last occurrence of the element in the receiver;
returns
-1if the element is not found. - Throws:
IndexOutOfBoundsException- index is out of range (size()>0 && (from<0 || from>to || to>=size())).
-
partFromTo
Returns a new list of the part of the receiver betweenfrom, inclusive, andto, inclusive.- Overrides:
partFromToin classAbstractByteList- 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())).
-
removeAll
Removes from the receiver all elements that are contained in the specified list. Tests for identity.- Overrides:
removeAllin classAbstractByteList- Parameters:
other- the other list.- Returns:
trueif the receiver changed as a result of the call.
-
replaceFromToWithFrom
Replaces a number of elements in the receiver with the same number of elements of another list. Replaces elements in the receiver, betweenfrom(inclusive) andto(inclusive), with elements ofother, starting fromotherFrom(inclusive).- Overrides:
replaceFromToWithFromin classAbstractByteList- Parameters:
from- the position of the first element to be replaced in the receiverto- the position of the last element to be replaced in the receiverother- list holding elements to be copied into the receiver.otherFrom- position of first element within other list to be copied.
-
retainAll
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.- Overrides:
retainAllin classAbstractByteList- Parameters:
other- the other list to test against.- Returns:
trueif 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.- Overrides:
reversein classAbstractByteList
-
set
public void set(int index, byte element) Replaces the element at the specified position in the receiver with the specified element.- Overrides:
setin classAbstractByteList- 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, byte 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().- Specified by:
setQuickin classAbstractByteList- 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 betweenfrom(inclusive) andto(inclusive).- Overrides:
shuffleFromToin classAbstractByteList- 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())).
-
sortFromTo
public void sortFromTo(int from, int to) Sorts the specified range of the receiver into ascending order. The sorting algorithm is countsort.- Overrides:
sortFromToin classAbstractList- 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())).
-
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:
trimToSizein classAbstractList
-