StringDict
- java.lang.Object
-
- processing.data.StringDict
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classStringDict.Entry
-
Constructor Summary
Constructors Constructor and Description StringDict()StringDict(java.io.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(int length)Create a new lookup pre-allocated to a specific length.
StringDict(java.lang.String[][] pairs)Constructor to allow (more intuitive) inline initialization, e.g.:
StringDict(java.lang.String[] keys, java.lang.String[] values)StringDict(TableRow row)Create a dictionary that maps between column titles and cell entries in a TableRow.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Remove all entries.
StringDictcopy()Returns a duplicate copy of this object.
java.lang.Iterable<StringDict.Entry>entries()java.util.Iterator<StringDict.Entry>entryIterator()java.lang.Stringget(java.lang.String key)Return a value for the specified key.
java.lang.Stringget(java.lang.String key, java.lang.String alternate)booleanhasKey(java.lang.String key)intindex(java.lang.String what)java.lang.Stringkey(int index)java.lang.String[]keyArray()Return a copy of the internal keys array.
java.lang.String[]keyArray(java.lang.String[] outgoing)java.util.Iterator<java.lang.String>keyIterator()java.lang.Iterable<java.lang.String>keys()voidprint()java.lang.Stringremove(java.lang.String key)java.lang.StringremoveIndex(int index)voidresize(int length)Resize the internal data, this can only be used to shrink the list.
voidsave(java.io.File file)Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
voidset(java.lang.String key, java.lang.String value)voidsetIndex(int index, java.lang.String key, java.lang.String value)intsize()voidsortKeys()Sort the keys alphabetically (ignoring case).
voidsortKeysReverse()voidsortValues()Sort by values in descending order (largest value will be at [0]).
voidsortValuesReverse()voidswap(int a, int b)java.lang.StringtoJSON()Return this dictionary as a String in JSON format.
java.lang.StringtoString()java.lang.Stringvalue(int index)java.lang.String[]valueArray()Create a new array and copy each of the values into it.
java.lang.String[]valueArray(java.lang.String[] array)Fill an already-allocated array with the values (more efficient than creating a new array each time).
java.util.Iterator<java.lang.String>valueIterator()java.lang.Iterable<java.lang.String>values()voidwrite(java.io.PrintWriter writer)Write tab-delimited entries to a PrintWriter
-
-
-
Constructor Detail
-
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
public StringDict(java.io.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
public StringDict(java.lang.String[] keys, java.lang.String[] values)
-
StringDict
public StringDict(java.lang.String[][] pairs)
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
public StringDict(TableRow row)
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 Detail
-
size
public int size()
- In brief:
- 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.
- In brief:
- Remove all entries
-
entries
public java.lang.Iterable<StringDict.Entry> entries()
-
entryIterator
public java.util.Iterator<StringDict.Entry> entryIterator()
-
key
public java.lang.String key(int index)
-
keys
public java.lang.Iterable<java.lang.String> keys()
-
keyIterator
public java.util.Iterator<java.lang.String> keyIterator()
-
keyArray
public java.lang.String[] keyArray()
Return a copy of the internal keys array. This array can be modified.
- In brief:
- Return a copy of the internal keys array
-
keyArray
public java.lang.String[] keyArray(java.lang.String[] outgoing)
-
value
public java.lang.String value(int index)
-
values
public java.lang.Iterable<java.lang.String> values()
- In brief:
- Return the internal array being used to store the values
-
valueIterator
public java.util.Iterator<java.lang.String> valueIterator()
-
valueArray
public java.lang.String[] valueArray()
Create a new array and copy each of the values into it.
- In brief:
- Create a new array and copy each of the values into it
-
valueArray
public java.lang.String[] valueArray(java.lang.String[] array)
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
public java.lang.String get(java.lang.String key)
Return a value for the specified key.
- In brief:
- Return a value for the specified key
-
get
public java.lang.String get(java.lang.String key, java.lang.String alternate)
-
set
public void set(java.lang.String key, java.lang.String value)- In brief:
- Create a new key/value pair or change the value of one
-
setIndex
public void setIndex(int index, java.lang.String key, java.lang.String value)
-
index
public int index(java.lang.String what)
-
hasKey
public boolean hasKey(java.lang.String key)
- In brief:
- Check if a key is a part of the data structure
-
remove
public java.lang.String remove(java.lang.String key)
- In brief:
- Remove a key/value pair
-
removeIndex
public java.lang.String removeIndex(int index)
-
swap
public void swap(int a, int b)
-
sortKeys
public void sortKeys()
Sort the keys alphabetically (ignoring case). Uses the value as a tie-breaker (only really possible with a key that has a case change).
- In brief:
- Sort the keys alphabetically
-
sortKeysReverse
public void sortKeysReverse()
- In brief:
- Sort the keys alphabetically in reverse
-
sortValues
public void sortValues()
Sort by values in descending order (largest value will be at [0]).
- In brief:
- Sort by values in ascending order
-
sortValuesReverse
public void sortValuesReverse()
- In brief:
- Sort by values in descending order
-
copy
public StringDict copy()
Returns a duplicate copy of this object.
-
print
public void print()
-
save
public void save(java.io.File file)
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
-
write
public void write(java.io.PrintWriter writer)
Write tab-delimited entries to a PrintWriter
-
toJSON
public java.lang.String toJSON()
Return this dictionary as a String in JSON format.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-