Package processing.data
Class DoubleList
java.lang.Object
processing.data.DoubleList
Helper class for a list of double values. Lists are designed
to have some features of ArrayList, but to maintain the
simplicity and efficiency of working with arrays.
Functions such as sort() and shuffle() always act on
the list itself. To get a sorted copy, use list.copy().sort().
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDoubleList
(double[] list) DoubleList
(int length) DoubleList
(Iterable<Object> iterator) Construct an FloatList from an iterable pile of objects.DoubleList
(Object... items) Construct an FloatList from a random pile of objects. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, double amount) void
append
(double value) Add a new entry to the list.void
append
(double[] values) void
append
(DoubleList list) void
appendUnique
(double value) Add this value, but only if it's not already in the list.double[]
array()
Deprecated.double[]
array
(double[] array) Deprecated.void
clear()
Remove all entries from the list.copy()
void
div
(int index, double amount) double
get
(int index) Get an entry at a particular index.Returns a normalized version of this array.getSubset
(int start) getSubset
(int start, int num) boolean
hasValue
(double value) int
index
(double what) Return the first index of a particular value.void
insert
(int index, double value) void
insert
(int index, double[] values) void
insert
(int index, DoubleList list) iterator()
Implemented this way so that we can use a FloatList in a for loop.double
max()
int
maxIndex()
double
min()
int
minIndex()
void
mult
(int index, double amount) double
pop()
void
print()
void
push
(double value) Just an alias for append(), but matches pop()double
random()
Return a random value from the list.double
remove
(int index) Remove an element from the specified index.double
int
removeValue
(int value) int
removeValues
(double value) boolean
replaceValue
(double value, double newValue) Replace the first instance of a particular valueboolean
replaceValues
(double value, double newValue) Replace all instances of a particular valuevoid
resize
(int length) void
reverse()
void
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)void
set
(int index, double what) Set the entry at a particular index.void
shuffle()
Randomize the order of the list elements.void
Randomize the list order using the random() function from the specified sketch, allowing shuffle() to use its current randomSeed() setting.int
size()
Get the length of the list.void
sort()
Sorts the array in place.void
Reverse sort, orders values from highest to lowestvoid
sub
(int index, double amount) double
sum()
double[]
toArray()
Create a new array with a copy of all the values.double[]
toArray
(double[] array) Copy values into the specified array.toJSON()
Return this dictionary as a String in JSON format.toString()
double[]
values()
Returns the actual array being used to store the data.void
write
(PrintWriter writer) Write entries to a PrintWriter, one per lineMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DoubleList
public DoubleList() -
DoubleList
public DoubleList(int length) -
DoubleList
public DoubleList(double[] list) -
DoubleList
Construct an FloatList from an iterable pile of objects. For instance, a double array, an array of strings, who knows. Un-parsable or null values will be set to NaN. -
DoubleList
Construct an FloatList from a random pile of objects. Un-parseable or null values will be set to NaN.
-
-
Method Details
-
size
public int size()Get the length of the list.- In brief:
- Get the length of the list
-
resize
public void resize(int length) -
clear
public void clear()Remove all entries from the list.- In brief:
- Remove all entries from the list
-
get
public double get(int index) Get an entry at a particular index.- In brief:
- Get an entry at a particular index
-
set
public void set(int index, double what) Set the entry at a particular index. If the index is past the length of the list, it'll expand the list to accommodate, and fill the intermediate entries with 0s.- In brief:
- Set the entry at a particular index
-
push
public void push(double value) Just an alias for append(), but matches pop() -
pop
public double pop() -
remove
public double remove(int index) Remove an element from the specified index.- In brief:
- Remove an element from the specified index
-
removeValue
public int removeValue(int value) -
removeValues
public int removeValues(double value) -
replaceValue
public boolean replaceValue(double value, double newValue) Replace the first instance of a particular value -
replaceValues
public boolean replaceValues(double value, double newValue) Replace all instances of a particular value -
append
public void append(double value) Add a new entry to the list.- In brief:
- Add a new entry to the list
-
append
public void append(double[] values) -
append
-
appendUnique
public void appendUnique(double value) Add this value, but only if it's not already in the list. -
insert
public void insert(int index, double value) -
insert
public void insert(int index, double[] values) -
insert
-
index
public int index(double what) Return the first index of a particular value. -
hasValue
public boolean hasValue(double value) - In brief:
- Check if a number is a part of the list
-
add
public void add(int index, double amount) - In brief:
- Add to a value
-
sub
public void sub(int index, double amount) - In brief:
- Subtract from a value
-
mult
public void mult(int index, double amount) - In brief:
- Multiply a value
-
div
public void div(int index, double amount) - In brief:
- Divide a value
-
min
public double min()- In brief:
- Return the smallest value
-
minIndex
public int minIndex() -
max
public double max()- In brief:
- Return the largest value
-
maxIndex
public int maxIndex() -
sum
public double sum() -
sort
public void sort()Sorts the array in place.- In brief:
- Sorts an array, lowest to highest
-
sortReverse
public void sortReverse()Reverse sort, orders values from highest to lowest- In brief:
- Reverse sort, orders values from highest to lowest
-
reverse
public void reverse()- In brief:
- Reverse the order of the list elements
-
shuffle
public void shuffle()Randomize the order of the list elements. Note that this does not obey the randomSeed() function in PApplet.- In brief:
- Randomize the order of the list elements
-
shuffle
Randomize the list order using the random() function from the specified sketch, allowing shuffle() to use its current randomSeed() setting. -
random
public double random()Return a random value from the list. -
removeChoice
public double removeChoice() -
copy
-
values
public double[] values()Returns the actual array being used to store the data. For advanced users, this is the fastest way to access a large list. Suitable for iterating with a for() loop, but modifying the list will have terrible consequences. -
iterator
Implemented this way so that we can use a FloatList in a for loop. -
array
Deprecated. -
toArray
public double[] toArray()Create a new array with a copy of all the values.- Returns:
- an array sized by the length of the list with each of the values.
- In brief:
- Create a new array with a copy of all the values
-
array
Deprecated. -
toArray
public double[] toArray(double[] array) Copy values into the specified array. If the specified array is null or not the same size, a new array will be allocated. -
getPercent
Returns a normalized version of this array. Called getPercent() for consistency with the Dict classes. It's a getter method because it needs to return a new list (because IntList/Dict can't do percentages or normalization in place on int values). -
getSubset
-
getSubset
-
join
-
print
public void print() -
save
Save tab-delimited entries to a file (TSV format, UTF-8 encoding) -
write
Write entries to a PrintWriter, one per line -
toJSON
Return this dictionary as a String in JSON format. -
toString
-