diff --git a/core/src/processing/data/FloatDict.java b/core/src/processing/data/FloatDict.java index eafa0943d..cb06c2b15 100644 --- a/core/src/processing/data/FloatDict.java +++ b/core/src/processing/data/FloatDict.java @@ -68,6 +68,28 @@ public class FloatDict { } } + + /** + * Constructor to allow (more intuitive) inline initialization, e.g.: + *
+   * new FloatDict(new Object[][] {
+   *   { "key1", 1 },
+   *   { "key2", 2 }
+   * });
+   * 
+ */ + public FloatDict(Object[][] pairs) { + count = pairs.length; + this.keys = new String[count]; + this.values = new float[count]; + for (int i = 0; i < count; i++) { + keys[i] = (String) pairs[i][0]; + values[i] = (Float) pairs[i][1]; + indices.put(keys[i], i); + } + } + + /** * @nowebref */ diff --git a/core/src/processing/data/IntDict.java b/core/src/processing/data/IntDict.java index 5b3efedbe..ba0bbaca0 100644 --- a/core/src/processing/data/IntDict.java +++ b/core/src/processing/data/IntDict.java @@ -83,6 +83,28 @@ public class IntDict { } } + + /** + * Constructor to allow (more intuitive) inline initialization, e.g.: + *
+   * new FloatDict(new Object[][] {
+   *   { "key1", 1 },
+   *   { "key2", 2 }
+   * });
+   * 
+ */ + public IntDict(Object[][] pairs) { + count = pairs.length; + this.keys = new String[count]; + this.values = new int[count]; + for (int i = 0; i < count; i++) { + keys[i] = (String) pairs[i][0]; + values[i] = (Integer) pairs[i][1]; + indices.put(keys[i], i); + } + } + + /** * Returns the number of key/value pairs * diff --git a/core/src/processing/data/StringDict.java b/core/src/processing/data/StringDict.java index cb65c7f9b..69fb4b716 100644 --- a/core/src/processing/data/StringDict.java +++ b/core/src/processing/data/StringDict.java @@ -69,6 +69,7 @@ public class StringDict { } } + /** * @nowebref */ @@ -84,6 +85,29 @@ public class StringDict { } } + + /** + * Constructor to allow (more intuitive) inline initialization, e.g.: + *
+   * new StringDict(new String[][] {
+   *   { "key1", "value1" },
+   *   { "key2", "value2" }
+   * });
+   * 
+ * 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 diff --git a/core/todo.txt b/core/todo.txt index 09921886c..1403530b4 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -3,6 +3,7 @@ X pop() was not implemented correctly X fairly major rewrite of createShape() X prevents same code from appearing 5x (!) in the source X improves bad api design with the static createShapeImpl() methods +X add new String/Int/FloatDict constructors for easier initialization _ need reference update for createShape() @@ -128,6 +129,7 @@ _ https://github.com/processing/processing/issues/2778 _ make join() work with Iterable? _ will this collide with the current String[] version? _ remove OPENGL constant (tell people to use P3D or P2D) +_ exec() and open() to use varargs under consideration diff --git a/todo.txt b/todo.txt index 467fe2d61..d114ed0d2 100644 --- a/todo.txt +++ b/todo.txt @@ -9,6 +9,9 @@ contribs X Window size not passing into Tweak Mode X https://github.com/processing/processing/issues/3208 X https://github.com/processing/processing/pull/3227 +X preferences window fixes for Linux +X https://github.com/processing/processing/pull/3232 +X https://github.com/processing/processing/issues/3231 _ we've lost arrow keys to expand items in the examples window