Package processing.data
Class StringDict
java.lang.Object
processing.data.StringDict
A simple class to use a String as a lookup for a String value. String "keys"
are associated with String values.
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionStringDict
(int length) Create a new lookup pre-allocated to a specific length.StringDict
(BufferedReader reader) Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab.StringDict
(String[][] pairs) Constructor to allow (more intuitive) inline initialization, e.g.:StringDict
(String[] keys, String[] values) StringDict
(TableRow row) Create a dictionary that maps between column titles and cell entries in a TableRow. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Remove all entries.copy()
Returns a duplicate copy of this object.entries()
Return a value for the specified key.boolean
Check if a key is a part of the data structureint
key
(int index) String[]
keyArray()
Return a copy of the internal keys array.String[]
keys()
Return the internal array being used to store the keys.void
print()
Remove a key/value pairremoveIndex
(int index) void
resize
(int length) Resize the internal data, this can only be used to shrink the list.void
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)void
Create a new key/value pair or change the value of onevoid
int
size()
Returns the number of key/value pairsvoid
sortKeys()
Sort the keys alphabetically.void
Sort the keys alphabetically in reversevoid
Sort by values in descending order.void
Sort by values in descending ordervoid
swap
(int a, int b) toJSON()
Return this dictionary as a String in JSON format.toString()
value
(int index) String[]
Create a new array and copy each of the values into it.String[]
valueArray
(String[] array) Fill an already-allocated array with the values (more efficient than creating a new array each time).values()
Return the internal array being used to store the valuesvoid
write
(PrintWriter writer) Write tab-delimited entries to a PrintWriter
-
Constructor Details
-
StringDict
public StringDict() -
StringDict
public StringDict(int length) Create a new lookup pre-allocated to a specific length. This will not change the size(), but is more efficient than not specifying a length. Use it when you know the rough size of the thing you're creating. -
StringDict
Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab. -
StringDict
-
StringDict
Constructor to allow (more intuitive) inline initialization, e.g.:new StringDict(new String[][] { { "key1", "value1" }, { "key2", "value2" } });
It's no Python, but beats a static { } block with HashMap.put() statements. -
StringDict
Create a dictionary that maps between column titles and cell entries in a TableRow. If two columns have the same name, the later column's values will override the earlier values.
-
-
Method Details
-
size
public int size()Returns the number of key/value pairs -
resize
public void resize(int length) Resize the internal data, this can only be used to shrink the list. Helpful for situations like sorting and then grabbing the top 50 entries. -
clear
public void clear()Remove all entries. -
entries
-
entryIterator
-
key
-
keys
Return the internal array being used to store the keys. -
keyIterator
-
keyArray
Return a copy of the internal keys array. -
keyArray
-
value
-
values
Return the internal array being used to store the values -
valueIterator
-
valueArray
Create a new array and copy each of the values into it. -
valueArray
Fill an already-allocated array with the values (more efficient than creating a new array each time). If 'array' is null, or not the same size as the number of values, a new array will be allocated and returned. -
get
Return a value for the specified key. -
get
-
set
Create a new key/value pair or change the value of one -
setIndex
-
index
-
hasKey
Check if a key is a part of the data structure -
remove
Remove a key/value pair -
removeIndex
-
swap
public void swap(int a, int b) -
sortKeys
public void sortKeys()Sort the keys alphabetically. -
sortKeysReverse
public void sortKeysReverse()Sort the keys alphabetically in reverse -
sortValues
public void sortValues()Sort by values in descending order. -
sortValuesReverse
public void sortValuesReverse()Sort by values in descending order -
copy
Returns a duplicate copy of this object. -
print
public void print() -
save
Save tab-delimited entries to a file (TSV format, UTF-8 encoding) -
write
Write tab-delimited entries to a PrintWriter -
toJSON
Return this dictionary as a String in JSON format. -
toString
-