- All Implemented Interfaces:
Iterable<Double>,Collection<Double>,List<Double>,SequencedCollection<Double>,DoubleList,DoubleSequencedCollection
A
double-valued list backed by a primitive array.- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty instance with 0 initial capacity.DoubleArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.DoubleArrayList(@NonNull Collection<Double> collection) Creates a new instance from the specified collection -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidAdds all items of the specified list to this list.<T extends Collection<Double>>
@NonNull TaddAllInto(@NonNull T out) Adds all items of this collection to the specified collection.voidaddAsDouble(double newItem) Adds a new item to the end of the list.voidaddAsDouble(int index, double newItem) Inserts a new item at the specified index into this list.voidvoidvoidclear()Clears the list in O(1).booleanvoidCopies the contents of this list into the provided array.Returns a stream for processing the items of this list.booleanget(int index) double[]getArray()Gets the array that is used internally by this list.doublegetAsDouble(int index) Gets the item at the specified index.getFirst()doublegetLast()doubleinthashCode()intindexOfAsDouble(double item) intindexOfAsDouble(double item, int start) booleanisEmpty()Returns true if size==0.iterator()Returns an iterator for this list.intlastIndexOfAsDouble(double item) intlastIndexOfAsDouble(double item, int start) static @NonNull DoubleArrayListCreates a new instance with the specified items.booleandoubleremoveAtAsDouble(int index) Removes the item at the specified index from this list.booleanremoveIfAsDouble(@NonNull DoublePredicate filter) Removes all the elements of this collection that satisfy the given predicate.doubleRemoves the last itemreversed()Replaces the item at the specified index.doublesetAsDouble(int index, double newItem) Replaces the item at the specified index.voidsetSize(int newSize) Sets the size of this list.intsize()Returns the size of the list.voidsort()Sorts the items in ascending order.voidsort(@Nullable Comparator<? super Double> c) Sorts this list according to the order induced by the specifiedComparator.Returns a spliterator for this list.double @NonNull []Returns a new array containing all the elements in this collection.toString()voidTrims the capacity of the list its current size.Methods inherited from class java.util.AbstractList
add, addAll, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.jhotdraw8.collection.primitive.DoubleList
addFirstAsDouble, addLastAsDouble, indexOf, lastIndexOf, removeFirstAsDoubleMethods inherited from interface org.jhotdraw8.collection.primitive.DoubleSequencedCollection
addLastAllAsDouble, addLastAllAsDoubleMethods inherited from interface java.util.List
add, addAll, addAll, containsAll, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, subList, toArray, toArray
-
Constructor Details
-
DoubleArrayList
public DoubleArrayList()Creates a new empty instance with 0 initial capacity. -
DoubleArrayList
public DoubleArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity
-
DoubleArrayList
Creates a new instance from the specified collection- Parameters:
collection- a collection of integers
-
-
Method Details
-
of
Creates a new instance with the specified items.- Parameters:
items- the items (the newly created instance references the provided array)- Returns:
- the new instance
-
addAsDouble
public void addAsDouble(double newItem) Adds a new item to the end of the list.- Specified by:
addAsDoublein interfaceDoubleList- Parameters:
newItem- the new item- See Also:
-
addAsDouble
public void addAsDouble(int index, double newItem) Inserts a new item at the specified index into this list.- Specified by:
addAsDoublein interfaceDoubleList- Parameters:
index- the indexnewItem- the new item- See Also:
-
addAllAsDouble
Adds all items of the specified list to this list.- Parameters:
that- another list
-
addAllInto
Adds all items of this collection to the specified collection.- Type Parameters:
T- the type of the collection- Parameters:
out- the output collection- Returns:
- out
-
clear
public void clear()Clears the list in O(1).- Specified by:
clearin interfaceCollection<Double>- Specified by:
clearin interfaceList<Double>- Overrides:
clearin classAbstractList<Double>
-
copyInto
Copies the contents of this list into the provided array.- Parameters:
a- an arrayoffset- the offset into the array
-
equals
- Specified by:
equalsin interfaceCollection<Double>- Specified by:
equalsin interfaceList<Double>- Overrides:
equalsin classAbstractList<Double>
-
getAsDouble
public double getAsDouble(int index) Gets the item at the specified index.- Specified by:
getAsDoublein interfaceDoubleList- Parameters:
index- an index- Returns:
- the item at the index
- See Also:
-
get
-
getLastAsDouble
public double getLastAsDouble()- Specified by:
getLastAsDoublein interfaceDoubleSequencedCollection
-
getFirstAsDouble
public double getFirstAsDouble()- Specified by:
getFirstAsDoublein interfaceDoubleSequencedCollection
-
setSize
public void setSize(int newSize) Sets the size of this list. If the new size is greater than the current size, new0items are added to the end of the list. If the new size is less than the current size, all items at indices greater or equalnewSizeare discarded.- Parameters:
newSize- the new size
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Double>- Specified by:
hashCodein interfaceList<Double>- Overrides:
hashCodein classAbstractList<Double>
-
indexOfAsDouble
public int indexOfAsDouble(double item) - Specified by:
indexOfAsDoublein interfaceDoubleList- See Also:
-
indexOfAsDouble
public int indexOfAsDouble(double item, int start) -
lastIndexOfAsDouble
public int lastIndexOfAsDouble(double item) - Specified by:
lastIndexOfAsDoublein interfaceDoubleList- See Also:
-
lastIndexOfAsDouble
public int lastIndexOfAsDouble(double item, int start) -
isEmpty
public boolean isEmpty()Returns true if size==0.- Specified by:
isEmptyin interfaceCollection<Double>- Specified by:
isEmptyin interfaceDoubleList- Specified by:
isEmptyin interfaceList<Double>- Overrides:
isEmptyin classAbstractCollection<Double>- Returns:
- true if empty
-
contains
- Specified by:
containsin interfaceCollection<Double>- Specified by:
containsin interfaceList<Double>- Overrides:
containsin classAbstractCollection<Double>
-
removeAtAsDouble
public double removeAtAsDouble(int index) Removes the item at the specified index from this list.- Specified by:
removeAtAsDoublein interfaceDoubleList- Parameters:
index- an index- Returns:
- the removed item
-
removeLastAsDouble
public double removeLastAsDouble()Removes the last item- Specified by:
removeLastAsDoublein interfaceDoubleSequencedCollection- Returns:
- the removed item
- Throws:
NoSuchElementException- if the list is empty
-
setAsDouble
public double setAsDouble(int index, double newItem) Replaces the item at the specified index.- Parameters:
index- an indexnewItem- the new item- Returns:
- the old item
-
set
Replaces the item at the specified index. -
size
public int size()Returns the size of the list.- Specified by:
sizein interfaceCollection<Double>- Specified by:
sizein interfaceList<Double>- Specified by:
sizein classAbstractCollection<Double>- Returns:
- the size
-
trimToSize
public void trimToSize()Trims the capacity of the list its current size. -
iterator
Returns an iterator for this list. -
spliterator
Returns a spliterator for this list.- Specified by:
spliteratorin interfaceCollection<Double>- Specified by:
spliteratorin interfaceIterable<Double>- Specified by:
spliteratorin interfaceList<Double>- Returns:
- a spliterator over the elements of this list
-
doubleStream
Returns a stream for processing the items of this list.- Returns:
- a stream
-
toDoubleArray
Returns a new array containing all the elements in this collection.- Returns:
- array
-
add
- Specified by:
addin interfaceCollection<Double>- Specified by:
addin interfaceDoubleList- Specified by:
addin interfaceList<Double>- Overrides:
addin classAbstractList<Double>
-
remove
- Specified by:
removein interfaceCollection<Double>- Specified by:
removein interfaceList<Double>- Overrides:
removein classAbstractCollection<Double>
-
toString
- Overrides:
toStringin classAbstractCollection<Double>
-
sort
public void sort()Sorts the items in ascending order. -
removeIfAsDouble
Removes all the elements of this collection that satisfy the given predicate.- Parameters:
filter- a predicate which returnstruefor elements to be removed- Returns:
trueif any elements were removed
-
sort
Sorts this list according to the order induced by the specifiedComparator. The sort is stable: it does not reorder equal elements.- Specified by:
sortin interfaceList<Double>- Parameters:
c- theComparatorused to compare list elements. Anullvalue indicates that the elements' natural ordering should be used.
-
reversed
-
getArray
public double[] getArray()Gets the array that is used internally by this list.- Returns:
- the internal array
-
addFirst
- Specified by:
addFirstin interfaceDoubleList- Specified by:
addFirstin interfaceDoubleSequencedCollection- Specified by:
addFirstin interfaceList<Double>- Specified by:
addFirstin interfaceSequencedCollection<Double>
-
addLast
- Specified by:
addLastin interfaceDoubleList- Specified by:
addLastin interfaceDoubleSequencedCollection- Specified by:
addLastin interfaceList<Double>- Specified by:
addLastin interfaceSequencedCollection<Double>
-
getFirst
- Specified by:
getFirstin interfaceDoubleList- Specified by:
getFirstin interfaceDoubleSequencedCollection- Specified by:
getFirstin interfaceList<Double>- Specified by:
getFirstin interfaceSequencedCollection<Double>
-
getLast
- Specified by:
getLastin interfaceDoubleList- Specified by:
getLastin interfaceDoubleSequencedCollection- Specified by:
getLastin interfaceList<Double>- Specified by:
getLastin interfaceSequencedCollection<Double>
-
removeFirst
- Specified by:
removeFirstin interfaceDoubleList- Specified by:
removeFirstin interfaceDoubleSequencedCollection- Specified by:
removeFirstin interfaceList<Double>- Specified by:
removeFirstin interfaceSequencedCollection<Double>
-
removeLast
- Specified by:
removeLastin interfaceDoubleList- Specified by:
removeLastin interfaceDoubleSequencedCollection- Specified by:
removeLastin interfaceList<Double>- Specified by:
removeLastin interfaceSequencedCollection<Double>
-