public class LongDict
extends Object
FloatDict
,
StringDict
Modifier and Type | Class and Description |
---|---|
class |
LongDict.Entry |
Constructor and Description |
---|
LongDict() |
LongDict(BufferedReader reader)
Read a set of entries from a Reader that has each key/value pair on
a single line, separated by a tab.
|
LongDict(int length)
Create a new lookup with a specific size.
|
LongDict(Object[][] pairs)
Constructor to allow (more intuitive) inline initialization, e.g.:
|
LongDict(String[] keys,
long[] values) |
Modifier and Type | Method and Description |
---|---|
void |
add(String key,
long amount) |
void |
clear()
Remove all entries.
|
LongDict |
copy()
Returns a duplicate copy of this object.
|
void |
div(String key,
long amount) |
Iterable<LongDict.Entry> |
entries() |
Iterator<LongDict.Entry> |
entryIterator() |
long |
get(String key)
Return a value for the specified key.
|
long |
get(String key,
long 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(String key) |
void |
increment(LongDict dict)
Merge another dictionary into this one.
|
void |
increment(String key)
Increase the value associated with a specific key by 1.
|
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() |
int |
maxIndex() |
String |
maxKey()
return the key corresponding to the maximum value or null if no entries
|
long |
maxValue() |
int |
minIndex() |
String |
minKey() |
long |
minValue() |
void |
mult(String key,
long amount) |
void |
print() |
long |
remove(String key) |
long |
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,
long amount)
Create a new key/value pair or change the value of one.
|
void |
setIndex(int index,
String key,
long 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(String key,
long amount) |
long |
sum() |
void |
swap(int a,
int b) |
String |
toJSON()
Return this dictionary as a String in JSON format.
|
String |
toString() |
long |
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).
|
Iterator<Long> |
valueIterator() |
Iterable<Long> |
values() |
void |
write(PrintWriter writer)
Write tab-delimited entries to a PrintWriter
|
public LongDict()
public LongDict(int length)
public LongDict(BufferedReader reader)
public LongDict(String[] keys, long[] values)
public LongDict(Object[][] pairs)
new FloatDict(new Object[][] { { "key1", 1 }, { "key2", 2 } });
public int size()
public void resize(int length)
public void clear()
public Iterable<LongDict.Entry> entries()
public Iterator<LongDict.Entry> entryIterator()
public String key(int index)
public Iterable<String> keys()
public Iterator<String> keyIterator()
public String[] keyArray()
public String[] keyArray(String[] outgoing)
public long value(int index)
public Iterable<Long> values()
public Iterator<Long> valueIterator()
public int[] valueArray()
public int[] valueArray(int[] array)
array
- values to copy into the arraypublic long get(String key)
public long get(String key, long alternate)
public void set(String key, long amount)
public void setIndex(int index, String key, long value)
public boolean hasKey(String key)
public void increment(String key)
public void increment(LongDict dict)
public void add(String key, long amount)
public void sub(String key, long amount)
public void mult(String key, long amount)
public void div(String key, long amount)
public int minIndex()
public String minKey()
public long minValue()
public int maxIndex()
public String maxKey()
public long maxValue()
public long sum()
public int index(String what)
public long remove(String key)
public long 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 LongDict copy()
public void print()
public void save(File file)
public void write(PrintWriter writer)
public String toJSON()
public String toString()
toString
in class Object