mirror of
https://github.com/processing/processing4.git
synced 2026-04-20 11:19:48 +02:00
fix how missing values are handled in dictionaries
This commit is contained in:
@@ -276,7 +276,18 @@ public class FloatDict {
|
||||
*/
|
||||
public float 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 float get(String key, float alternate) {
|
||||
int index = index(key);
|
||||
if (index == -1) {
|
||||
return alternate;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -246,6 +246,14 @@ public class StringDict {
|
||||
return values[index];
|
||||
}
|
||||
|
||||
|
||||
public String get(String key, String alternate) {
|
||||
int index = index(key);
|
||||
if (index == -1) return alternate;
|
||||
return values[index];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @webref stringdict:method
|
||||
* @brief Create a new key/value pair or change the value of one
|
||||
|
||||
Reference in New Issue
Block a user