public class IntDict
extends java.lang.Object
FloatDict
,
StringDict
Modifier and Type | Class and Description |
---|---|
class |
IntDict.Entry |
Constructor and Description |
---|
IntDict() |
IntDict(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.
|
IntDict(int length)
Create a new lookup with a specific size.
|
IntDict(java.lang.Object[][] pairs)
Constructor to allow (more intuitive) inline initialization, e.g.:
|
IntDict(java.lang.String[] keys,
int[] values) |
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String key,
int amount) |
void |
clear()
Remove all entries.
|
IntDict |
copy()
Returns a duplicate copy of this object.
|
void |
div(java.lang.String key,
int amount) |
java.lang.Iterable<IntDict.Entry> |
entries() |
java.util.Iterator<IntDict.Entry> |
entryIterator() |
int |
get(java.lang.String key)
Return a value for the specified key.
|
int |
get(java.lang.String key,
int alternate) |
FloatDict |
getPercent()
Sum all of the values in this dictionary, then return a new FloatDict of
each key, divided by the total sum.
|
boolean |
hasKey(java.lang.String key) |
void |
increment(IntDict dict)
Merge another dictionary into this one.
|
void |
increment(java.lang.String key)
Increase the value associated with a specific key by 1.
|
int |
index(java.lang.String what) |
java.lang.String |
key(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() |
int |
maxIndex() |
java.lang.String |
maxKey()
return the key corresponding to the maximum value or null if no entries
|
int |
maxValue() |
int |
minIndex() |
java.lang.String |
minKey() |
int |
minValue() |
void |
mult(java.lang.String key,
int amount) |
void |
print() |
int |
remove(java.lang.String key) |
int |
removeIndex(int index) |
void |
resize(int length)
Resize the internal data, this can only be used to shrink the list.
|
void |
save(java.io.File file)
Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
|
void |
set(java.lang.String key,
int amount)
Create a new key/value pair or change the value of one.
|
void |
setIndex(int index,
java.lang.String key,
int value) |
int |
size()
Returns the number of key/value pairs
|
void |
sortKeys()
Sort the keys alphabetically (ignoring case).
|
void |
sortKeysReverse()
Sort the keys alphabetically in reverse (ignoring case).
|
void |
sortValues()
Sort by values in ascending order.
|
void |
sortValues(boolean stable)
Set true to ensure that the order returned is identical.
|
void |
sortValuesReverse()
Sort by values in descending order.
|
void |
sortValuesReverse(boolean stable) |
void |
sub(java.lang.String key,
int amount) |
int |
sum() |
long |
sumLong() |
void |
swap(int a,
int b) |
java.lang.String |
toJSON()
Return this dictionary as a String in JSON format.
|
java.lang.String |
toString() |
int |
value(int index) |
int[] |
valueArray()
Create a new array and copy each of the values into it.
|
int[] |
valueArray(int[] array)
Fill an already-allocated array with the values (more efficient than
creating a new array each time).
|
java.util.Iterator<java.lang.Integer> |
valueIterator() |
java.lang.Iterable<java.lang.Integer> |
values() |
void |
write(java.io.PrintWriter writer)
Write tab-delimited entries to a PrintWriter
|
public IntDict()
public IntDict(int length)
public IntDict(java.io.BufferedReader reader)
public IntDict(java.lang.String[] keys, int[] values)
public IntDict(java.lang.Object[][] pairs)
new FloatDict(new Object[][] { { "key1", 1 }, { "key2", 2 } });
public int size()
public void resize(int length)
public void clear()
public java.lang.Iterable<IntDict.Entry> entries()
public java.util.Iterator<IntDict.Entry> entryIterator()
public java.lang.String key(int index)
public java.lang.Iterable<java.lang.String> keys()
public java.util.Iterator<java.lang.String> keyIterator()
public java.lang.String[] keyArray()
public java.lang.String[] keyArray(java.lang.String[] outgoing)
public int value(int index)
public java.lang.Iterable<java.lang.Integer> values()
public java.util.Iterator<java.lang.Integer> valueIterator()
public int[] valueArray()
public int[] valueArray(int[] array)
array
- values to copy into the arraypublic int get(java.lang.String key)
public int get(java.lang.String key, int alternate)
public void set(java.lang.String key, int amount)
public void setIndex(int index, java.lang.String key, int value)
public boolean hasKey(java.lang.String key)
public void increment(java.lang.String key)
public void increment(IntDict dict)
public void add(java.lang.String key, int amount)
public void sub(java.lang.String key, int amount)
public void mult(java.lang.String key, int amount)
public void div(java.lang.String key, int amount)
public int minIndex()
public java.lang.String minKey()
public int minValue()
public int maxIndex()
public java.lang.String maxKey()
public int maxValue()
public int sum()
public long sumLong()
public int index(java.lang.String what)
public int remove(java.lang.String key)
public int removeIndex(int index)
public void swap(int a, int b)
public void sortKeys()
public void sortKeysReverse()
public void sortValues()
public void sortValues(boolean stable)
stable
- public void sortValuesReverse()
public void sortValuesReverse(boolean stable)
public FloatDict getPercent()
public IntDict copy()
public void print()
public void save(java.io.File file)
public void write(java.io.PrintWriter writer)
public java.lang.String toJSON()
public java.lang.String toString()
toString
in class java.lang.Object