From 2327009d883e9506776071ca649e0b46c37a81e9 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 10 Oct 2017 20:34:40 -0400 Subject: [PATCH] add setIndex() method --- core/src/processing/data/FloatDict.java | 9 +++++++++ core/src/processing/data/IntDict.java | 10 ++++++++++ core/src/processing/data/StringDict.java | 10 ++++++++++ 3 files changed, 29 insertions(+) diff --git a/core/src/processing/data/FloatDict.java b/core/src/processing/data/FloatDict.java index dbb89ecee..dc35f4b99 100644 --- a/core/src/processing/data/FloatDict.java +++ b/core/src/processing/data/FloatDict.java @@ -346,6 +346,15 @@ public class FloatDict { } + public void setIndex(int index, String key, float value) { + if (index < 0 || index >= count) { + throw new ArrayIndexOutOfBoundsException(index); + } + keys[index] = key; + values[index] = value; + } + + /** * @webref floatdict:method * @brief Check if a key is a part of the data structure diff --git a/core/src/processing/data/IntDict.java b/core/src/processing/data/IntDict.java index e3f5805b9..6ef168b46 100644 --- a/core/src/processing/data/IntDict.java +++ b/core/src/processing/data/IntDict.java @@ -348,6 +348,16 @@ public class IntDict { } } + + public void setIndex(int index, String key, int value) { + if (index < 0 || index >= count) { + throw new ArrayIndexOutOfBoundsException(index); + } + keys[index] = key; + values[index] = value; + } + + /** * @webref intdict:method * @brief Check if a key is a part of the data structure diff --git a/core/src/processing/data/StringDict.java b/core/src/processing/data/StringDict.java index a5d83fd09..e34d4663f 100644 --- a/core/src/processing/data/StringDict.java +++ b/core/src/processing/data/StringDict.java @@ -363,11 +363,21 @@ public class StringDict { } + public void setIndex(int index, String key, String value) { + if (index < 0 || index >= count) { + throw new ArrayIndexOutOfBoundsException(index); + } + keys[index] = key; + values[index] = value; + } + + public int index(String what) { Integer found = indices.get(what); return (found == null) ? -1 : found.intValue(); } + /** * @webref stringdict:method * @brief Check if a key is a part of the data structure