Modifier and Type | Class and Description |
---|---|
class |
StringDict.Entry |
Constructor and Description |
---|
StringDict() |
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(int length)
Create a new lookup pre-allocated to a specific length.
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Remove all entries.
|
StringDict |
copy()
Returns a duplicate copy of this object.
|
Iterable<StringDict.Entry> |
entries() |
Iterator<StringDict.Entry> |
entryIterator() |
String |
get(String key)
Return a value for the specified key.
|
String |
get(String key,
String alternate) |
boolean |
hasKey(String key) |
int |
index(String what) |
String |
key(int index) |
String[] |
keyArray()
Return a copy of the internal keys array.
|
String[] |
keyArray(String[] outgoing) |
Iterator<String> |
keyIterator() |
Iterable<String> |
keys() |
void |
print() |
String |
remove(String key) |
String |
removeIndex(int index) |
void |
resize(int length)
Resize the internal data, this can only be used to shrink the list.
|
void |
save(File file)
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
|
void |
set(String key,
String value) |
void |
setIndex(int index,
String key,
String value) |
int |
size() |
void |
sortKeys()
Sort the keys alphabetically (ignoring case).
|
void |
sortKeysReverse() |
void |
sortValues()
Sort by values in descending order (largest value will be at [0]).
|
void |
sortValuesReverse() |
void |
swap(int a,
int b) |
String |
toJSON()
Return this dictionary as a String in JSON format.
|
String |
toString() |
String |
value(int index) |
String[] |
valueArray()
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).
|
Iterator<String> |
valueIterator() |
Iterable<String> |
values() |
void |
write(PrintWriter writer)
Write tab-delimited entries to a PrintWriter
|
public StringDict()
public StringDict(int length)
public StringDict(BufferedReader reader)
public StringDict(String[] keys, String[] values)
public StringDict(String[][] pairs)
new StringDict(new String[][] { { "key1", "value1" }, { "key2", "value2" } });It's no Python, but beats a static { } block with HashMap.put() statements.
public StringDict(TableRow row)
public int size()
public void resize(int length)
public void clear()
public Iterable<StringDict.Entry> entries()
public Iterator<StringDict.Entry> entryIterator()
public String key(int index)
public Iterable<String> keys()
public Iterator<String> keyIterator()
public String[] keyArray()
public String[] keyArray(String[] outgoing)
public String value(int index)
public Iterable<String> values()
public Iterator<String> valueIterator()
public String[] valueArray()
public String[] valueArray(String[] array)
public String get(String key)
public String get(String key, String alternate)
public void set(String key, String value)
public void setIndex(int index, String key, String value)
public int index(String what)
public boolean hasKey(String key)
public String remove(String key)
public String removeIndex(int index)
public void swap(int a, int b)
public void sortKeys()
public void sortKeysReverse()
public void sortValues()
public void sortValuesReverse()
public StringDict copy()
public void print()
public void save(File file)
public void write(PrintWriter writer)
public String toJSON()
public String toString()
toString
in class Object