From 01cb9f504c860bc1c037a44f3a76bf342a293d46 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 22 Mar 2016 12:28:35 -0400 Subject: General formatting cleanup and documentation update --- .../src/main/java/bjc/utils/data/GenHolder.java | 23 +++++++------ .../src/main/java/bjc/utils/data/IHolder.java | 24 ++++++++----- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 34 +++++++++++++----- .../src/main/java/bjc/utils/data/IPrecedent.java | 15 ++++---- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 33 +++++++++++------- .../main/java/bjc/utils/data/lazy/LazyHolder.java | 28 +++++++-------- .../main/java/bjc/utils/data/lazy/LazyPair.java | 40 +++++++++++++++++++--- 7 files changed, 130 insertions(+), 67 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') 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 fba801b..5cf35ae 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java @@ -32,13 +32,23 @@ public class GenHolder implements IHolder { * Creates a new holder, with its state initialized to the provided * value * - * @param held + * @param hld * The state to initialize this holder to. */ public GenHolder(T hld) { held = hld; } + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer) + */ + @Override + public void doWith(Consumer f) { + f.accept(held); + } + /* * (non-Javadoc) * @@ -46,7 +56,7 @@ public class GenHolder implements IHolder { */ @Override public IHolder map(Function f) { - return new GenHolder(f.apply(held)); + return new GenHolder<>(f.apply(held)); } /* @@ -70,13 +80,4 @@ public class GenHolder implements IHolder { public E unwrap(Function f) { return f.apply(held); } - - /* - * (non-Javadoc) - * - * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer) - */ - public void doWith(Consumer f) { - f.accept(held); - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java index ddcb2f6..3675842 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -14,9 +14,20 @@ import java.util.function.Function; */ public interface IHolder { + /** + * Call a provided function with the value being held + * + * @param f + * The function to call + */ + public void doWith(Consumer f); + /** * Return the result of applying the given transformation to the held - * value Doesn't change the held value + * value. Doesn't change the held value. + * + * @param + * The new type of the held value * * @param f * The transformation to apply @@ -37,17 +48,12 @@ public interface IHolder { /** * Returns a raw mapped value, not contained in a GenHolder * + * @param + * The type of the value that is the end result + * * @param f * The function to use for mapping the value * @return The mapped value outside of a GenHolder */ public E unwrap(Function f); - - /** - * Call a provided function with the value being held - * - * @param f - * The function to call - */ - public void doWith(Consumer f); } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index fcf2b05..9923099 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -4,12 +4,27 @@ import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; +/** + * An interface representing a pair of values + * + * @author ben + * + * @param + * The type stored in the left side of the pair + * @param + * The type stored in the right side of the pair + */ public interface IPair { /** * Create a new pair by applying the given functions to the left/right. * Does not change the internal contents of this pair. * + * @param + * The new left type of the pair + * @param + * The new right type of the pair + * * @param lf * The function to apply to the left value. * @param rf @@ -19,22 +34,23 @@ public interface IPair { public IPair apply(Function lf, Function rf); + /** + * Execute an action with the values of this pair. Has no effect on the + * internal contents + * + * @param bc + * The action to execute on the values + */ + public void doWith(BiConsumer bc); + /** * Collapse this pair to a single value. Does not change the internal * contents of this pair. + * @param The resulting type after merging * * @param bf * The function to use to collapse the pair. * @return The collapsed value. */ public E merge(BiFunction bf); - - /** - * Execute an action with the values of this pair. Has no effect on the - * internal contents - * - * @param bc - * The action to execute on the values - */ - public void doWith(BiConsumer bc); } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java index 1e00a59..a9ae0bc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java @@ -6,14 +6,8 @@ package bjc.utils.data; * @author ben * */ +@FunctionalInterface public interface IPrecedent { - /** - * Get the precedence of the attached object - * - * @return The precedence of the attached object - */ - public int getPrecedence(); - /** * Create a new object with set precedence * @@ -24,4 +18,11 @@ public interface IPrecedent { public static IPrecedent newSimplePrecedent(int prec) { return () -> prec; } + + /** + * Get the precedence of the attached object + * + * @return The precedence of the attached object + */ + public int getPrecedence(); } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java index 4e7f6ae..4a8fbc3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -7,6 +7,8 @@ import java.util.function.Function; /** * Holds a pair of values of two different types. * + * Is an eager variant of {@link IPair} + * * @author ben * * @param @@ -45,28 +47,35 @@ public class Pair implements IPair { r = right; } - /* (non-Javadoc) - * @see bjc.utils.data.IPair#apply(java.util.function.Function, java.util.function.Function) + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IPair#apply(java.util.function.Function, + * java.util.function.Function) */ @Override public IPair apply(Function lf, Function rf) { - return new Pair(lf.apply(l), rf.apply(r)); + return new Pair<>(lf.apply(l), rf.apply(r)); } - /* (non-Javadoc) - * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) - */ - @Override - public E merge(BiFunction bf) { - return bf.apply(l, r); - } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer) */ @Override public void doWith(BiConsumer bc) { bc.accept(l, r); } + + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) + */ + @Override + public E merge(BiFunction bf) { + return bf.apply(l, r); + } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java index 43dec86..6321cc2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java @@ -21,9 +21,9 @@ import bjc.utils.funcdata.FunctionalList; */ public class LazyHolder implements IHolder { /** - * The source for a value held by this lazy holder + * List of queued actions to be performed on realized values */ - private Supplier heldSrc; + private FunctionalList> actions; /** * The value internally held by this lazy holder @@ -31,9 +31,9 @@ public class LazyHolder implements IHolder { private T held; /** - * List of queued actions to be performed on realized values + * The source for a value held by this lazy holder */ - private FunctionalList> actions; + private Supplier heldSrc; /** * Create a new lazy holder with the given supplier @@ -57,9 +57,18 @@ public class LazyHolder implements IHolder { held = val; } + @Override + public void doWith(Consumer f) { + transform((val) -> { + f.accept(val); + + return val; + }); + } + @Override public IHolder map(Function f) { - return new LazyHolder(() -> { + return new LazyHolder<>(() -> { if (held == null) { return actions.reduceAux(heldSrc.get(), Function::apply, f::apply); @@ -89,13 +98,4 @@ public class LazyHolder implements IHolder { return f.apply(held); } - @Override - public void doWith(Consumer f) { - transform((val) -> { - f.accept(val); - - return val; - }); - } - } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java index 2aab4ce..bd02b52 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java @@ -6,20 +6,41 @@ import java.util.function.Function; import bjc.utils.data.IPair; +/** + * A lazy holder of two values + * + * Lazy variant of {@link IPair} + * + * @author ben + * + * @param + * The type of value stored on the left side of the pair + * @param + * The type of value stored on the right side of the pair + */ public class LazyPair implements IPair { + /** + * The backing store for this pair + */ protected LazyHolder> del; + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IPair#apply(java.util.function.Function, + * java.util.function.Function) + */ @Override public IPair apply(Function lf, Function rf) { return del.unwrap((par) -> par.apply(lf, rf)); } - @Override - public E merge(BiFunction bf) { - return del.unwrap((par) -> par.merge(bf)); - } - + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer) + */ @Override public void doWith(BiConsumer bc) { del.doWith((par) -> { @@ -27,4 +48,13 @@ public class LazyPair implements IPair { }); } + /* + * (non-Javadoc) + * + * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) + */ + @Override + public E merge(BiFunction bf) { + return del.unwrap((par) -> par.merge(bf)); + } } -- cgit v1.2.3