- 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
public class SortedArrayList<E> extends ArrayList<E>
ASortedArrayListstores its elements in hashCode order and provides means of quickly locating objects.- Author:
- AO Industries, Inc.
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description SortedArrayList()Constructs an empty list with an initial capacity of ten.SortedArrayList(int initialCapacity)Constructs an empty list with the specified initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)Not allowed to add to specific indexes.booleanadd(E o)Adds 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 hashCodeintindexOf(Object elem)Searches 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.booleanremove(Object o)Removes a single instance of the specified element from this list, if it is present (optional operation).Eset(int index, E element)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 Detail
-
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 Detail
-
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
public int indexOf(Object elem)
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
public int lastIndexOf(Object elem)
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.
-
add
public boolean add(E o)
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
public void add(int index, E element)Not allowed to add to specific indexes.
-
remove
public boolean remove(Object o)
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
public boolean addAll(Collection<? extends E> c)
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.
-
-