Skip to content

Commit f3c9855

Browse files
committed
add appendUnique() to Int/Float/StringList
1 parent c8aa5b1 commit f3c9855

5 files changed

Lines changed: 31 additions & 1 deletion

File tree

build/shared/revisions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Not quite ready for prime time, however.
5757

5858
+ Added StringList(Object...) constructor to handle a grab bag of objects
5959

60+
+ Added appendUnique() to Int/Float/StringList to only add unique items
61+
to a list. Replaces the following code, making "set" operations easier:
62+
if (!theList.hasValue(value)) {
63+
thiList.append(value);
64+
}
65+
6066
+ Inside main(), don't set 'args' to a zero-length array if no args
6167
were passed in, instead leave 'args' null.
6268

core/src/processing/data/FloatList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ public void append(FloatList list) {
285285
}
286286

287287

288+
/** Add this value, but only if it's not already in the list. */
289+
public void appendUnique(float value) {
290+
if (!hasValue(value)) {
291+
append(value);
292+
}
293+
}
294+
295+
288296
// public void insert(int index, int value) {
289297
// if (index+1 > count) {
290298
// if (index+1 < data.length) {

core/src/processing/data/IntList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ public void append(IntList list) {
254254
}
255255

256256

257+
/** Add this value, but only if it's not already in the list. */
258+
public void appendUnique(int value) {
259+
if (!hasValue(value)) {
260+
append(value);
261+
}
262+
}
263+
264+
257265
// public void insert(int index, int value) {
258266
// if (index+1 > count) {
259267
// if (index+1 < data.length) {

core/src/processing/data/StringList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ public void append(StringList list) {
314314
}
315315

316316

317+
/** Add this value, but only if it's not already in the list. */
318+
public void appendUnique(String value) {
319+
if (!hasValue(value)) {
320+
append(value);
321+
}
322+
}
323+
324+
317325
// public void insert(int index, int value) {
318326
// if (index+1 > count) {
319327
// if (index+1 < data.length) {

core/todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ X this was fixed earlier?
3838
X fix flicker when resizing window
3939
X running through PSurfaceAWT.setSize() is probably overkill
4040
o setLocationRelativeTo(null) was removed, will it be missed?
41+
X add appendUnique() to Int/Float/StringList
4142

4243
opengl
4344
X OpenGL sketches work only after running a sketch with default renderer
@@ -193,7 +194,6 @@ _ map() is bad for Python and JavaScript
193194

194195

195196
data
196-
_ add appendUnique()
197197
_ add fromOrder() and others? otherwise need temp object:
198198
_ categoryIndexLookup = new StringList(flavors).getOrder();
199199
_ handling of 'missing' values in Table needs serious work

0 commit comments

Comments
 (0)