From a3a95154666eb0fbae948173d13ad72c5509b1c4 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 29 Feb 2016 09:05:36 -0500 Subject: Factored interface out of GenHolder --- .../src/main/java/bjc/utils/data/GenHolder.java | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java index 390982a..d6266ca 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java @@ -7,12 +7,14 @@ import java.util.function.Function; * references to data, and more specifically for accessing non-final * variables from a lambda. AKA the identity monad * + * This is an eager variant of {@link IHolder} + * * @author ben * * @param * The type of the data being held */ -public class GenHolder { +public class GenHolder implements IHolder { /** * The state this holder is responsible for. */ @@ -36,39 +38,34 @@ public class GenHolder { held = hld; } - /** - * Return the result of applying the given transformation to the held - * value Doesn't change the held value + /* + * (non-Javadoc) * - * @param f - * The transformation to apply - * @return A holder with the transformed value + * @see bjc.utils.data.IHolder#map(java.util.function.Function) */ - public GenHolder map(Function f) { + @Override + public IHolder map(Function f) { return new GenHolder(f.apply(held)); } - /** - * Apply the given transformation to the held value. Returns the holder - * for allowing chaining of transforms + /* + * (non-Javadoc) * - * @param f - * The transform to apply to the value - * @return The holder + * @see bjc.utils.data.IHolder#transform(java.util.function.Function) */ - public GenHolder transform(Function f) { + @Override + public IHolder transform(Function f) { held = f.apply(held); return this; } - /** - * Returns a raw mapped value, not contained in a GenHolder + /* + * (non-Javadoc) * - * @param f - * The function to use for mapping the value - * @return The mapped value outside of a GenHolder + * @see bjc.utils.data.IHolder#unwrap(java.util.function.Function) */ + @Override public E unwrap(Function f) { return f.apply(held); } -- cgit v1.2.3