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
ConstructorsConstructorDescriptionConstructs 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 TypeMethodDescriptionvoidNot allowed to add to specific indexes.booleanAdds the specified element in sorted position within this list.booleanaddAll(int index, Collection<? extends E> c) Not allowed to add to a specific index.booleanaddAll(Collection<? extends E> c) Adds all of the elements in the specified Collection and sorts during the add.protected intbinarySearchHashCode(int elemHash) Performs a binary search on hashCode values only.intindexOf(int hashCode) Finds the first index where the object has the provided hashCode.intSearches for the first occurrence of the given argument, testing for equality using theequalsmethod.intlastIndexOf(Object elem) Returns the index of the last occurrence of the specified object in this list.booleanRemoves 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, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods 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 theequalsmethod. -
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:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin 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. Returnstrueif 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.
-
