Package processing.data
Class IntList
java.lang.Object
processing.data.IntList
Helper class for a list of int 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, int amount) Add to a value.void
append
(int value) Add a new entry to the list.void
append
(int[] values) void
void
appendUnique
(int value) Add this value, but only if it's not already in the list.int[]
array()
Deprecated.int[]
array
(int[] array) Deprecated.int
choice()
Return a random value from the list.void
clear()
Remove all entries from the list.copy()
void
div
(int index, int amount) Divide a value.static IntList
fromRange
(int stop) static IntList
fromRange
(int start, int stop) int
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
(int value) Check if a number is a part of the data structure.void
increment
(int index) Add one to a value.int
index
(int what) Return the first index of a particular value.void
insert
(int index, int value) void
insert
(int index, int[] values) void
iterator()
int
max()
Return the largest value.int
maxIndex()
int
min()
Return the smallest value.int
minIndex()
void
mult
(int index, int amount) Multiply a value.int
pop()
void
print()
void
push
(int value) Just an alias for append(), but matches pop()int
remove
(int index) Remove an element from the specified indexint
int
removeValue
(int value) int
removeValues
(int value) void
resize
(int length) void
reverse()
Reverse the order of the list.void
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)void
set
(int index, int 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, lowest to highest.void
A sort in reverse.void
sub
(int index, int amount) Subtract from a value.int
sum()
long
sumLong()
int[]
toArray()
Create a new array with a copy of all the values.int[]
toArray
(int[] array) Copy values into the specified array.toJSON()
Return this dictionary as a String in JSON format.toString()
int[]
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
-
IntList
public IntList() -
IntList
public IntList(int length) -
IntList
public IntList(int[] source) -
IntList
Construct an IntList from an iterable pile of objects. For instance, a float array, an array of strings, who knows. Un-parsable or null values will be set to 0. -
IntList
Construct an IntList from a random pile of objects. Un-parsable or null values will be set to zero.
-
-
Method Details
-
fromRange
-
fromRange
-
size
public int size()Get the length of the list. -
resize
public void resize(int length) -
clear
public void clear()Remove all entries from the list. -
get
public int get(int index) Get an entry at a particular index. -
set
public void set(int index, int what) Set the entry at a particular index. -
push
public void push(int value) Just an alias for append(), but matches pop() -
pop
public int pop() -
remove
public int remove(int index) Remove an element from the specified index -
removeValue
public int removeValue(int value) -
removeValues
public int removeValues(int value) -
append
public void append(int value) Add a new entry to the list. -
append
public void append(int[] values) -
append
-
appendUnique
public void appendUnique(int value) Add this value, but only if it's not already in the list. -
insert
public void insert(int index, int value) -
insert
public void insert(int index, int[] values) -
insert
-
index
public int index(int what) Return the first index of a particular value. -
hasValue
public boolean hasValue(int value) Check if a number is a part of the data structure. -
increment
public void increment(int index) Add one to a value. -
add
public void add(int index, int amount) Add to a value. -
sub
public void sub(int index, int amount) Subtract from a value. -
mult
public void mult(int index, int amount) Multiply a value. -
div
public void div(int index, int amount) Divide a value. -
min
public int min()Return the smallest value. -
minIndex
public int minIndex() -
max
public int max()Return the largest value. -
maxIndex
public int maxIndex() -
sum
public int sum() -
sumLong
public long sumLong() -
sort
public void sort()Sorts the array, lowest to highest. -
sortReverse
public void sortReverse()A sort in reverse. It's equivalent to running sort() and then reverse(), but is more efficient than running each separately. -
reverse
public void reverse()Reverse the order of the list. -
shuffle
public void shuffle()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. -
choice
public int choice()Return a random value from the list. -
removeChoice
public int removeChoice() -
copy
-
values
public int[] 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
-
array
Deprecated. -
toArray
public int[] 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.
-
array
Deprecated. -
toArray
public int[] toArray(int[] 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
-