public class DoubleDict
extends Object
IntDict
,
StringDict
Modifier and Type | Class and Description |
---|---|
class |
DoubleDict.Entry |
Constructor and Description |
---|
DoubleDict() |
DoubleDict(BufferedReader reader)
Read a set of entries from a Reader that has each key/value pair on
a single line, separated by a tab.
|
DoubleDict(int length)
Create a new lookup with a specific size.
|
DoubleDict(Map<String,Double> incoming) |
DoubleDict(Object[][] pairs)
Constructor to allow (more intuitive) inline initialization, e.g.:
|
DoubleDict(String[] keys,
double[] values) |
Modifier and Type | Method and Description |
---|---|
void |
add(String key,
double amount) |
void |
clear()
Remove all entries.
|
DoubleDict |
copy()
Returns a duplicate copy of this object.
|
void |
div(String key,
double amount) |
Iterable<DoubleDict.Entry> |
entries() |
Iterator<DoubleDict.Entry> |
entryIterator() |
double |
get(String key)
Return a value for the specified key.
|
double |
get(String key,
double alternate) |
DoubleDict |
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) |
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()
The key for a max value; null if empty or everything is NaN (no max).
|
double |
maxValue()
The max value.
|
int |
minIndex() |
String |
minKey() |
double |
minValue() |
void |
mult(String key,
double amount) |
void |
print() |
double |
remove(String key) |
double |
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,
double amount) |
void |
setIndex(int index,
String key,
double 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 |
sortValues(boolean stable)
Set true to ensure that the order returned is identical.
|
void |
sortValuesReverse() |
void |
sortValuesReverse(boolean stable) |
void |
sub(String key,
double amount) |
double |
sum() |
void |
swap(int a,
int b) |
String |
toJSON()
Return this dictionary as a String in JSON format.
|
String |
toString() |
double |
value(int index) |
double[] |
valueArray()
Create a new array and copy each of the values into it.
|
double[] |
valueArray(double[] array)
Fill an already-allocated array with the values (more efficient than
creating a new array each time).
|
Iterator<Double> |
valueIterator() |
Iterable<Double> |
values() |
void |
write(PrintWriter writer)
Write tab-delimited entries out to
|
public DoubleDict()
public DoubleDict(int length)
public DoubleDict(BufferedReader reader)
public DoubleDict(String[] keys, double[] values)
public DoubleDict(Object[][] pairs)
new FloatDict(new Object[][] { { "key1", 1 }, { "key2", 2 } });
public DoubleDict(Map<String,Double> incoming)
public int size()
public void resize(int length)
public void clear()
public Iterable<DoubleDict.Entry> entries()
public Iterator<DoubleDict.Entry> entryIterator()
public String key(int index)
public Iterable<String> keys()
public Iterator<String> keyIterator()
public String[] keyArray()
public String[] keyArray(String[] outgoing)
public double value(int index)
public Iterable<Double> values()
public Iterator<Double> valueIterator()
public double[] valueArray()
public double[] valueArray(double[] array)
public double get(String key)
public double get(String key, double alternate)
public void set(String key, double amount)
public void setIndex(int index, String key, double value)
public boolean hasKey(String key)
public void add(String key, double amount)
public void sub(String key, double amount)
public void mult(String key, double amount)
public void div(String key, double amount)
public int minIndex()
public String minKey()
public double minValue()
public int maxIndex()
public String maxKey()
public double maxValue()
public double sum()
public int index(String what)
public double remove(String key)
public double 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 DoubleDict getPercent()
public DoubleDict copy()
public void print()
public void save(File file)
public void write(PrintWriter writer)
writer
- public String toJSON()
public String toString()
toString
in class Object