diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-07 13:04:43 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-07 13:04:43 -0300 |
| commit | f8f9166be2c5d02edc17b3fb1d4ea6baa9f926da (patch) | |
| tree | 7f6897a4bf112e57bbfb8b435b0a72dfede09c94 /base/src/main/java/bjc/utils/funcdata/FunctionalList.java | |
| parent | ca2a5c012267c500d9f0fd883c98904d125a64f0 (diff) | |
Update
Diffstat (limited to 'base/src/main/java/bjc/utils/funcdata/FunctionalList.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/funcdata/FunctionalList.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java index c730424..6953bd0 100644 --- a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -169,6 +169,33 @@ public class FunctionalList<E> implements Cloneable, IList<E> { } @Override + public E last() { + if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to get last element of empty list"); + + return wrapped.get(wrapped.size() - 1); + } + + @Override + public E popFirst() { + if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to pop first element of empty list"); + + E head = first(); + wrapped.remove(0); + + return head; + } + + @Override + public E popLast() { + if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to pop last element of empty list"); + + E tail = last(); + wrapped.remove(wrapped.size() - 1); + + return tail; + } + + @Override public <T> IList<T> flatMap(final Function<E, IList<T>> expander) { if(expander == null) throw new NullPointerException("Expander must not be null"); |
