From 70db057aef813a423b4c77dcb22c8b5bc3972f92 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Mon, 7 May 2018 18:33:52 -0400 Subject: [PATCH] construct a DoubleDict from a Map --- core/src/processing/data/DoubleDict.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/processing/data/DoubleDict.java b/core/src/processing/data/DoubleDict.java index c8297df6e..e310b079e 100644 --- a/core/src/processing/data/DoubleDict.java +++ b/core/src/processing/data/DoubleDict.java @@ -3,6 +3,7 @@ package processing.data; import java.io.*; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import processing.core.PApplet; @@ -106,6 +107,20 @@ public class DoubleDict { } + public DoubleDict(Map incoming) { + count = incoming.size(); + keys = new String[count]; + values = new double[count]; + int index = 0; + for (Map.Entry e : incoming.entrySet()) { + keys[index] = e.getKey(); + values[index] = e.getValue(); + indices.put(keys[index], index); + index++; + } + } + + /** * @webref doubledict:method * @brief Returns the number of key/value pairs