From 6e5f8a1dae7a2a9b18354597253cc7aec1b5fce8 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 17 May 2015 11:46:20 -0400 Subject: [PATCH] add appendUnique() to Int/Float/StringList --- build/shared/revisions.txt | 6 ++++++ core/src/processing/data/FloatList.java | 8 ++++++++ core/src/processing/data/IntList.java | 8 ++++++++ core/src/processing/data/StringList.java | 8 ++++++++ core/todo.txt | 2 +- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 0ed683c7c..05c4f3526 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -57,6 +57,12 @@ Not quite ready for prime time, however. + Added StringList(Object...) constructor to handle a grab bag of objects ++ Added appendUnique() to Int/Float/StringList to only add unique items + to a list. Replaces the following code, making "set" operations easier: + if (!theList.hasValue(value)) { + thiList.append(value); + } + + Inside main(), don't set 'args' to a zero-length array if no args were passed in, instead leave 'args' null. diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index bc39a3ae3..5862cc7c8 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -285,6 +285,14 @@ public class FloatList implements Iterable { } + /** Add this value, but only if it's not already in the list. */ + public void appendUnique(float value) { + if (!hasValue(value)) { + append(value); + } + } + + // public void insert(int index, int value) { // if (index+1 > count) { // if (index+1 < data.length) { diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index e9a310361..c90390eba 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -254,6 +254,14 @@ public class IntList implements Iterable { } + /** Add this value, but only if it's not already in the list. */ + public void appendUnique(int value) { + if (!hasValue(value)) { + append(value); + } + } + + // public void insert(int index, int value) { // if (index+1 > count) { // if (index+1 < data.length) { diff --git a/core/src/processing/data/StringList.java b/core/src/processing/data/StringList.java index 42f807cee..a647a9191 100644 --- a/core/src/processing/data/StringList.java +++ b/core/src/processing/data/StringList.java @@ -314,6 +314,14 @@ public class StringList implements Iterable { } + /** Add this value, but only if it's not already in the list. */ + public void appendUnique(String value) { + if (!hasValue(value)) { + append(value); + } + } + + // public void insert(int index, int value) { // if (index+1 > count) { // if (index+1 < data.length) { diff --git a/core/todo.txt b/core/todo.txt index 196883fe6..70c27a1f4 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -38,6 +38,7 @@ X this was fixed earlier? X fix flicker when resizing window X running through PSurfaceAWT.setSize() is probably overkill o setLocationRelativeTo(null) was removed, will it be missed? +X add appendUnique() to Int/Float/StringList opengl X OpenGL sketches work only after running a sketch with default renderer @@ -193,7 +194,6 @@ _ map() is bad for Python and JavaScript data -_ add appendUnique() _ add fromOrder() and others? otherwise need temp object: _ categoryIndexLookup = new StringList(flavors).getOrder(); _ handling of 'missing' values in Table needs serious work