From 889fac2bdf993dc86f64a8893c0260fdcf848acb Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:40:33 -0400 Subject: Cleanup --- .../src/main/java/bjc/utils/esodata/Stack.java | 111 +++++++++++---------- 1 file changed, 58 insertions(+), 53 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java index 217c671..9d74e9a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java @@ -17,21 +17,26 @@ import java.util.function.Consumer; * thrown. Check the size of the stack if you want to avoid this. *

*

- * + * * @param * The datatype stored in the stack. - * + * * @author Ben Culkin */ public abstract class Stack { /** * The exception thrown when attempting to access an element from the * stack that isn't there. - * + * * @author EVE * */ public static class StackUnderflowException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1423867176204571539L; } /** @@ -52,7 +57,7 @@ public abstract class Stack { /** * Retrieve the top element of this stack without removing it from the * stack. - * + * * @return The top element of this stack. */ public abstract T top(); @@ -90,7 +95,7 @@ public abstract class Stack { * @param n * The number of items to drop. */ - public void drop(int n) { + public void drop(final int n) { for (int i = 0; i < n; i++) { pop(); } @@ -109,8 +114,8 @@ public abstract class Stack { * @param n * The number of items below the top to delete. */ - public void nip(int n) { - T elm = pop(); + public void nip(final int n) { + final T elm = pop(); drop(n); @@ -132,15 +137,15 @@ public abstract class Stack { * @param m * The number of times to duplicate items. */ - public void multidup(int n, int m) { - List lst = new ArrayList<>(n); + public void multidup(final int n, final int m) { + final List lst = new ArrayList<>(n); for (int i = n; i > 0; i--) { lst.set(i - 1, pop()); } for (int i = 0; i < m; i++) { - for (T elm : lst) { + for (final T elm : lst) { push(elm); } } @@ -152,7 +157,7 @@ public abstract class Stack { * @param n * The number of items to duplicate. */ - public void dup(int n) { + public void dup(final int n) { multidup(n, 2); } @@ -171,22 +176,22 @@ public abstract class Stack { * @param m * The number of times to duplicate items. */ - public void multiover(int n, int m) { - List lst = new ArrayList<>(n); + public void multiover(final int n, final int m) { + final List lst = new ArrayList<>(n); - T elm = pop(); + final T elm = pop(); for (int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (T nelm : lst) { + for (final T nelm : lst) { push(nelm); } push(elm); for (int i = 1; i < m; i++) { - for (T nelm : lst) { + for (final T nelm : lst) { push(nelm); } } @@ -198,7 +203,7 @@ public abstract class Stack { * @param n * The number of items to duplicate. */ - public void over(int n) { + public void over(final int n) { multiover(n, 2); } @@ -213,9 +218,9 @@ public abstract class Stack { * Duplicate the third item in the stack. */ public void pick() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(x); push(y); @@ -227,8 +232,8 @@ public abstract class Stack { * Swap the top two items on the stack. */ public void swap() { - T y = pop(); - T x = pop(); + final T y = pop(); + final T x = pop(); push(y); push(x); @@ -238,8 +243,8 @@ public abstract class Stack { * Duplicate the second item below the first item. */ public void deepdup() { - T y = pop(); - T x = pop(); + final T y = pop(); + final T x = pop(); push(x); push(x); @@ -250,9 +255,9 @@ public abstract class Stack { * Swap the second and third items in the stack. */ public void deepswap() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(y); push(x); @@ -263,9 +268,9 @@ public abstract class Stack { * Rotate the top three items on the stack */ public void rot() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(y); push(z); @@ -276,9 +281,9 @@ public abstract class Stack { * Inversely rotate the top three items on the stack */ public void invrot() { - T z = pop(); - T y = pop(); - T x = pop(); + final T z = pop(); + final T y = pop(); + final T x = pop(); push(z); push(x); @@ -296,8 +301,8 @@ public abstract class Stack { * @param cons * The action to hide the elements from */ - public void dip(int n, Consumer> cons) { - List elms = new ArrayList<>(n); + public void dip(final int n, final Consumer> cons) { + final List elms = new ArrayList<>(n); for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); @@ -305,7 +310,7 @@ public abstract class Stack { cons.accept(this); - for (T elm : elms) { + for (final T elm : elms) { push(elm); } } @@ -316,7 +321,7 @@ public abstract class Stack { * @param cons * The action to hide the top from */ - public void dip(Consumer> cons) { + public void dip(final Consumer> cons) { dip(1, cons); } @@ -329,7 +334,7 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void keep(int n, Consumer> cons) { + public void keep(final int n, final Consumer> cons) { dup(n); dip(n, cons); } @@ -342,15 +347,15 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void multicleave(int n, List>> conses) { - List elms = new ArrayList<>(n); + public void multicleave(final int n, final List>> conses) { + final List elms = new ArrayList<>(n); for (int i = n; i > 0; i--) { elms.set(i - 1, pop()); } - for (Consumer> cons : conses) { - for (T elm : elms) { + for (final Consumer> cons : conses) { + for (final T elm : elms) { push(elm); } @@ -364,7 +369,7 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void cleave(List>> conses) { + public void cleave(final List>> conses) { multicleave(1, conses); } @@ -376,11 +381,11 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void multispread(int n, List>> conses) { - List> nelms = new ArrayList<>(conses.size()); + public void multispread(final int n, final List>> conses) { + final List> nelms = new ArrayList<>(conses.size()); for (int i = conses.size(); i > 0; i--) { - List elms = new ArrayList<>(n); + final List elms = new ArrayList<>(n); for (int j = n; j > 0; j--) { elms.set(j, pop()); @@ -390,8 +395,8 @@ public abstract class Stack { } int i = 0; - for (List elms : nelms) { - for (T elm : elms) { + for (final List elms : nelms) { + for (final T elm : elms) { push(elm); } @@ -406,7 +411,7 @@ public abstract class Stack { * @param conses * The actions to execute. */ - public void spread(List>> conses) { + public void spread(final List>> conses) { multispread(1, conses); } @@ -420,8 +425,8 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void multiapply(int n, int m, Consumer> cons) { - List>> conses = new ArrayList<>(m); + public void multiapply(final int n, final int m, final Consumer> cons) { + final List>> conses = new ArrayList<>(m); for (int i = 0; i < m; i++) { conses.add(cons); @@ -438,7 +443,7 @@ public abstract class Stack { * @param cons * The action to execute. */ - public void apply(int n, Consumer> cons) { + public void apply(final int n, final Consumer> cons) { multiapply(1, n, cons); } @@ -447,7 +452,7 @@ public abstract class Stack { */ /** * Get an array representing this stack. - * + * * @return The stack as an array. */ public abstract T[] toArray(); -- cgit v1.2.3