From f4baa925b0b5590bc8b12ba5f32e0218384c8efc Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 7 Apr 2017 16:06:18 -0400 Subject: Add simple toggle values --- .../src/main/java/bjc/utils/funcdata/IList.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java index cf60ed6..d92d564 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -41,6 +41,28 @@ public interface IList extends Iterable { return items.map(this::add).anyMatch(bl -> bl == false); } + /** + * Add all of the elements in the provided array to this list. + * + * @param items + * The array of items to add. + * + * @return True if every item was successfully added to the list, false + * otherwise. + */ + @SuppressWarnings("unchecked") + default boolean addAll(ContainedType... items) { + boolean succ = true; + + for(ContainedType item : items) { + boolean addSucc = add(item); + + succ = succ ? addSucc : false; + } + + return succ; + } + /** * Check if all of the elements of this list match the specified * predicate. @@ -237,6 +259,19 @@ public interface IList extends Iterable { */ void prepend(ContainedType item); + /** + * Prepend an array of items to the list. + * + * @param items + * The items to prepend to the list. + */ + @SuppressWarnings("unchecked") + default void prependAll(ContainedType... items) { + for(ContainedType item : items) { + prepend(item); + } + } + /** * Select a random item from the list, using a default random number * generator -- cgit v1.2.3