Package processing.data
Class StringList
java.lang.Object
processing.data.StringList
Helper class for a list of String objects. 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().
-
Constructor Summary
ConstructorDescriptionStringList
(int length) StringList
(Iterable<String> iterable) Create from something iterable, for instance: StringList list = new StringList(hashMap.keySet());StringList
(Object... items) Construct a StringList from a random pile of objects.StringList
(String[] list) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new entry to the list.void
void
append
(StringList list) void
appendUnique
(String value) Add this value, but only if it's not already in the list.String[]
array()
Deprecated.String[]
Deprecated.choice()
Return a random value from the list.void
clear()
Remove all entries from the list.copy()
get
(int index) Get an entry at a particular index.getOrder()
Create a dictionary associating each entry in this list to its index.getSubset
(int start) getSubset
(int start, int num) getTally()
Count the number of times each String entry is found in this list.String[]
Get a list of all unique entries.boolean
Check if a value is a part of the listint
Return the first index of a particular value.void
void
void
insert
(int index, StringList list) iterator()
void
lower()
Make the entire list lower case.pop()
void
print()
void
Just an alias for append(), but matches pop()remove
(int index) Remove an element from the specified index.int
removeValue
(String value) int
removeValues
(String value) int
replaceValue
(String value, String newValue) int
replaceValues
(String value, String newValue) void
resize
(int length) void
reverse()
Reverse the order of the listvoid
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)void
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
A sort in reverse.String[]
toArray()
Create a new array with a copy of all the values.String[]
Copy values into the specified array.toJSON()
Return this dictionary as a String in JSON format.toString()
void
upper()
Make the entire list upper case.String[]
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
-
StringList
public StringList() -
StringList
public StringList(int length) -
StringList
-
StringList
Construct a StringList from a random pile of objects. Null values will stay null, but all the others will be converted to String values. -
StringList
Create from something iterable, for instance: StringList list = new StringList(hashMap.keySet());
-
-
Method Details
-
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
Get an entry at a particular index. -
set
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 null. -
push
Just an alias for append(), but matches pop() -
pop
-
remove
Remove an element from the specified index. -
removeValue
-
removeValues
-
replaceValue
-
replaceValues
-
append
Add a new entry to the list. -
append
-
append
-
appendUnique
Add this value, but only if it's not already in the list. -
insert
-
insert
-
insert
-
index
Return the first index of a particular value. -
hasValue
Check if a value is a part of the list -
sort
public void sort()Sorts the array in place. -
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
Return a random value from the list. Throws an exception if there are no entries available. (Can't just return null because IntList and FloatList can't do that, and would be inconsistent.) -
removeChoice
-
lower
public void lower()Make the entire list lower case. -
upper
public void upper()Make the entire list upper case. -
copy
-
values
Returns the actual array being used to store the data. Suitable for iterating with a for() loop, but modifying the list could cause terrible things to happen. -
iterator
-
array
Deprecated. -
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
Copy values into the specified array. If the specified array is null or not the same size, a new array will be allocated. -
getSubset
-
getSubset
-
getUnique
Get a list of all unique entries. -
getTally
Count the number of times each String entry is found in this list. -
getOrder
Create a dictionary associating each entry in this list to its index. -
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
-