From 6eff1da1b9c09f2c4e12dfd247edf3d3d6061256 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 25 Apr 2015 03:08:25 -0400 Subject: [PATCH] add push() and pop() to String/Int/FloatList --- core/src/processing/data/FloatList.java | 16 ++++++++++++++++ core/src/processing/data/IntList.java | 16 ++++++++++++++++ core/src/processing/data/StringList.java | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index 625850a1e..bc39a3ae3 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -137,6 +137,22 @@ public class FloatList implements Iterable { } + /** Just an alias for append(), but matches pop() */ + public void push(float value) { + append(value); + } + + + public float pop() { + if (count == 0) { + throw new RuntimeException("Can't call pop() on an empty list"); + } + float value = get(count-1); + count--; + return value; + } + + /** * Remove an element from the specified index. * diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index c591d3ae8..e9a310361 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -157,6 +157,22 @@ public class IntList implements Iterable { } + /** Just an alias for append(), but matches pop() */ + public void push(int value) { + append(value); + } + + + public int pop() { + if (count == 0) { + throw new RuntimeException("Can't call pop() on an empty list"); + } + int value = get(count-1); + count--; + return value; + } + + /** * Remove an element from the specified index * diff --git a/core/src/processing/data/StringList.java b/core/src/processing/data/StringList.java index 595affdcb..65d73ceb9 100644 --- a/core/src/processing/data/StringList.java +++ b/core/src/processing/data/StringList.java @@ -140,6 +140,22 @@ public class StringList implements Iterable { } + /** Just an alias for append(), but matches pop() */ + public void push(String value) { + append(value); + } + + + public String pop() { + if (count == 0) { + throw new RuntimeException("Can't call pop() on an empty list"); + } + String value = get(count-1); + count--; + return value; + } + + /** * Remove an element from the specified index. *