add push() and pop() to String/Int/FloatList

This commit is contained in:
Ben Fry
2015-04-25 03:08:25 -04:00
parent 1c189ab5f3
commit 6eff1da1b9
3 changed files with 48 additions and 0 deletions

View File

@@ -137,6 +137,22 @@ public class FloatList implements Iterable<Float> {
}
/** 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.
*

View File

@@ -157,6 +157,22 @@ public class IntList implements Iterable<Integer> {
}
/** 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
*

View File

@@ -140,6 +140,22 @@ public class StringList implements Iterable<String> {
}
/** 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.
*