Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / util / SimpleStack.java
diff --git a/core/src/net/sf/openrocket/util/SimpleStack.java b/core/src/net/sf/openrocket/util/SimpleStack.java
new file mode 100644 (file)
index 0000000..6bdd967
--- /dev/null
@@ -0,0 +1,29 @@
+package net.sf.openrocket.util;
+
+import java.util.NoSuchElementException;
+/**
+ * SimpleStack implementation backed by an ArrayList.
+ * 
+ */
+public class SimpleStack<T> extends ArrayList<T> {
+
+       public void push( T value ) {
+               this.add(value);
+       }
+       
+       public T peek() {
+               if ( size() <= 0 ) {
+                       return null;
+               }
+               return this.get( size() -1 );
+       }
+       
+       public T pop() {
+               if ( size() <= 0 ) {
+                       throw new NoSuchElementException();
+               }
+               T value = this.remove( size() -1 );
+               return value;
+       }
+       
+}