fix how missing values are handled in dictionaries

This commit is contained in:
Ben Fry
2014-11-07 09:30:25 -05:00
parent 33b2adbfe2
commit 920a0e0e94
3 changed files with 31 additions and 2 deletions

View File

@@ -298,10 +298,20 @@ public class IntDict {
*/
public int get(String key) {
int index = index(key);
if (index == -1) return 0;
if (index == -1) {
throw new IllegalArgumentException("No key named '" + key + "'");
}
return values[index];
}
public int get(String key, int alternate) {
int index = index(key);
if (index == -1) return alternate;
return values[index];
}
/**
* Create a new key/value pair or change the value of one.
*