mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 13:49:18 +01:00
add new String/Int/FloatDict constructors for easier initialization
This commit is contained in:
@@ -69,6 +69,7 @@ public class StringDict {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @nowebref
|
||||
*/
|
||||
@@ -84,6 +85,29 @@ public class StringDict {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor to allow (more intuitive) inline initialization, e.g.:
|
||||
* <pre>
|
||||
* new StringDict(new String[][] {
|
||||
* { "key1", "value1" },
|
||||
* { "key2", "value2" }
|
||||
* });
|
||||
* </pre>
|
||||
* It's no Python, but beats a static { } block with HashMap.put() statements.
|
||||
*/
|
||||
public StringDict(String[][] pairs) {
|
||||
count = pairs.length;
|
||||
this.keys = new String[count];
|
||||
this.values = new String[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
keys[i] = pairs[i][0];
|
||||
values[i] = pairs[i][1];
|
||||
indices.put(keys[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @webref stringdict:method
|
||||
* @brief Returns the number of key/value pairs
|
||||
|
||||
Reference in New Issue
Block a user