From d7648dd32feedd293be253f827d0a9618d53d043 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 21 Feb 2016 15:40:55 -0500 Subject: Some refactoring of other packages --- .../src/main/java/bjc/utils/data/GenHolder.java | 61 +++++++++++++--------- 1 file changed, 35 insertions(+), 26 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 f969960..f5d553c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java @@ -3,61 +3,70 @@ package bjc.utils.data; import java.util.function.Function; /** - * Holds a single value of a specific type. - * This is used for indirect references to data, and more specifically - * for accessing non-final variables from a lambda. - * AKA the identity monad + * Holds a single value of a specific type. This is used for indirect + * references to data, and more specifically for accessing non-final + * variables from a lambda. AKA the identity monad + * * @author ben * - * @param The type of the data being held + * @param + * The type of the data being held */ public class GenHolder { /** * The state this holder is responsible for. */ public T held; - + /** * Creates a new empty holder, with its state set to null */ public GenHolder() { held = null; } - + /** - * Creates a new holder, with its state initialized to the provided value + * Creates a new holder, with its state initialized to the provided + * value * - * @param held The state to initialize this holder to. + * @param held + * The state to initialize this holder to. */ public GenHolder(T hld) { held = hld; } - + + /** + * Return the result of applying the given transformation to the held + * value Doesn't change the held value + * + * @param f + * The transformation to apply + * @return A holder with the transformed value + */ + public GenHolder 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 - * @param f The transform to apply to the value + * Apply the given transformation to the held value. Returns the holder + * for allowing chaining of transforms + * + * @param f + * The transform to apply to the value * @return The holder */ public GenHolder transform(Function f) { held = f.apply(held); - + return this; } - - /** - * Return the result of applying the given transformation to the held value - * Doesn't change the held value - * @param f The transformation to apply - * @return A holder with the transformed value - */ - public GenHolder map(Function f) { - return new GenHolder(f.apply(held)); - } - + /** * Returns a raw mapped value, not contained in a GenHolder - * @param f The function to use for mapping the value + * + * @param f + * The function to use for mapping the value * @return The mapped value outside of a GenHolder */ public E unwrap(Function f) { -- cgit v1.2.3