- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<Long>
-
- com.aoapps.collections.LongArrayList
-
- com.aoapps.collections.SortedLongArrayList
-
- All Implemented Interfaces:
LongCollection,LongList,Serializable,Cloneable,Iterable<Long>,Collection<Long>,List<Long>,RandomAccess
public class SortedLongArrayList extends LongArrayList implements Cloneable, Serializable
ASortedLongArrayListstores is elements in numerical order and provides means of quickly locating objects.- Author:
- AO Industries, Inc.
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.aoapps.collections.LongArrayList
elementData, size
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description SortedLongArrayList()Constructs an empty list with an initial capacity of ten.SortedLongArrayList(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, long element)Not allowed to add to specific indexes.booleanadd(long o)Adds the specified element in sorted position within this list.booleanaddAll(int index, Collection<? extends Long> c)Not allowed to add to a specific index.booleanaddAll(Collection<? extends Long> c)Adds all of the elements in the specified Collection and sorts during the add.protected intbinarySearch(long value)Performs a binary search for the provide value.Objectclone()Returns a shallow copy of thisLongArrayListinstance.intindexOf(long elem)Searches for the first occurrence of the given value.intlastIndexOf(long elem)Returns the index of the last occurrence of the specified object in this list.booleanremoveByValue(long value)Removes a single instance of the specified element from this list, if it is present (optional operation).longset(int index, long element)Not allowed to set specific indexes.-
Methods inherited from class com.aoapps.collections.LongArrayList
add, add, clear, contains, contains, ensureCapacity, get, getLong, indexOf, isEmpty, lastIndexOf, remove, remove, removeAtIndex, removeRange, set, size, toArray, toArray, toArrayLong, trimToSize
-
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
-
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, replaceAll, retainAll, sort, spliterator, subList
-
-
-
-
Constructor Detail
-
SortedLongArrayList
public SortedLongArrayList(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
-
SortedLongArrayList
public SortedLongArrayList()
Constructs an empty list with an initial capacity of ten.
-
-
Method Detail
-
clone
public Object clone()
Description copied from class:LongArrayListReturns a shallow copy of thisLongArrayListinstance. (The elements themselves are not copied.)- Overrides:
clonein classLongArrayList- Returns:
- a clone of this
LongArrayListinstance.
-
binarySearch
protected int binarySearch(long value)
Performs a binary search for the provide value. It will return any matching element, not necessarily the first or the last.
-
indexOf
public int indexOf(long elem)
Searches for the first occurrence of the given value.- Specified by:
indexOfin interfaceLongList- Overrides:
indexOfin classLongArrayList- Parameters:
elem- the value- Returns:
- the index of the first occurrence of the argument in this
list; returns
-1if the object is not found. - See Also:
Object.equals(Object)
-
lastIndexOf
public int lastIndexOf(long elem)
Returns the index of the last occurrence of the specified object in this list.- Specified by:
lastIndexOfin interfaceLongList- Overrides:
lastIndexOfin classLongArrayList- 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
public long set(int index, long element)Not allowed to set specific indexes.- Specified by:
setin interfaceLongList- Overrides:
setin classLongArrayList- Parameters:
index- index of element to replace.element- element to be stored at the specified position.- Returns:
- the element previously at the specified position.
-
add
public boolean add(long o)
Adds the specified element in sorted position within this list.- Specified by:
addin interfaceLongCollection- Overrides:
addin classLongArrayList- Parameters:
o- element to be appended to this list.- Returns:
true(as per the general contract of Collection.add).
-
add
public void add(int index, long element)Not allowed to add to specific indexes.- Specified by:
addin interfaceLongList- Overrides:
addin classLongArrayList- Parameters:
index- index at which the specified element is to be inserted.element- element to be inserted.
-
removeByValue
public boolean removeByValue(long value)
Removes a single instance of the specified element from this list, if it is present (optional operation). More formally, removes an elementesuch that(o==null ? e==null : o.equals(e)), 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).- Specified by:
removeByValuein interfaceLongCollection- Overrides:
removeByValuein classLongArrayList- Parameters:
value- element to be removed from this list, if present.- Returns:
trueif the list contained the specified element.
-
addAll
public boolean addAll(Collection<? extends Long> 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.- Specified by:
addAllin interfaceCollection<Long>- Specified by:
addAllin interfaceList<Long>- Overrides:
addAllin classLongArrayList- Parameters:
c- the elements to be inserted into this list.- Returns:
trueif this list changed as a result of the call.
-
addAll
public boolean addAll(int index, Collection<? extends Long> c)Not allowed to add to a specific index.- Specified by:
addAllin interfaceList<Long>- Overrides:
addAllin classLongArrayList- Parameters:
index- index at which to insert first element from the specified collection.c- elements to be inserted into this list.- Returns:
trueif this list changed as a result of the call.
-
-