java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
com.aoapps.collections.SortedArrayList<E>
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
A
SortedArrayList
stores its elements in hashCode order and provides means of quickly
locating objects.- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionConstructs an empty list with an initial capacity of ten.SortedArrayList
(int initialCapacity) Constructs an empty list with the specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Not allowed to add to specific indexes.boolean
Adds the specified element in sorted position within this list.boolean
addAll
(int index, Collection<? extends E> c) Not allowed to add to a specific index.boolean
addAll
(Collection<? extends E> c) Adds all of the elements in the specified Collection and sorts during the add.protected int
binarySearchHashCode
(int elemHash) Performs a binary search on hashCode values only.int
indexOf
(int hashCode) Finds the first index where the object has the provided hashCode.int
Searches for the first occurrence of the given argument, testing for equality using theequals
method.int
lastIndexOf
(Object elem) Returns the index of the last occurrence of the specified object in this list.boolean
Removes a single instance of the specified element from this list, if it is present (optional operation).Not allowed to set specific indexes.Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, isEmpty, iterator, listIterator, listIterator, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll
-
Constructor Details
-
SortedArrayList
public SortedArrayList(int initialCapacity) Constructs an empty list with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list.- Throws:
IllegalArgumentException
- if the specified initial capacity is negative
-
SortedArrayList
public SortedArrayList()Constructs an empty list with an initial capacity of ten.
-
-
Method Details
-
binarySearchHashCode
protected int binarySearchHashCode(int elemHash) Performs a binary search on hashCode values only. It will return any matching element, not necessarily the first or the last. -
indexOf
Searches for the first occurrence of the given argument, testing for equality using theequals
method. -
indexOf
public int indexOf(int hashCode) Finds the first index where the object has the provided hashCode. -
lastIndexOf
Returns the index of the last occurrence of the specified object in this list.- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classArrayList<E>
- Parameters:
elem
- the desired element.- Returns:
- the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.
-
set
Not allowed to set specific indexes. -
add
Adds the specified element in sorted position within this list. When two elements have the same hashCode, the new item is added at the end of the list of matching hashCodes. -
add
Not allowed to add to specific indexes. -
remove
Removes a single instance of the specified element from this list, if it is present (optional operation). If the list contains one or more such elements. Returnstrue
if the list contained the specified element (or equivalently, if the list changed as a result of the call). -
addAll
Adds all of the elements in the specified Collection and sorts during the add. This may operate slowly as it is the same as individual calls to the add method. -
addAll
Not allowed to add to a specific index.
-