From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../main/java/bjc/utils/funcutils/FuncUtils.java | 56 +++++++++++----------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'base/src/main/java/bjc/utils/funcutils/FuncUtils.java') diff --git a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java index ff9fefb..70e521a 100644 --- a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java @@ -13,38 +13,35 @@ import java.util.function.UnaryOperator; */ public class FuncUtils { /** - * Convert a binary function into a unary function that returns a - * function. + * Convert a binary function into a unary function that returns a function. * * @param - * The initial type of the function. + * The initial type of the function. * * @param - * The intermediate type of the function. + * The intermediate type of the function. * * @param - * The terminal type of the function. + * The terminal type of the function. * * @param func - * The function to transform. + * The function to transform. * - * @return The function transformed into a unary function returning a - * function. + * @return The function transformed into a unary function returning a function. */ - public static Function> curry2(final BiFunction func) { - return arg1 -> arg2 -> { - return func.apply(arg1, arg2); - }; + public static Function> + curry2(final BiFunction func) { + return arg1 -> arg2 -> func.apply(arg1, arg2); } /** * Do the specified action the specified number of times. * * @param nTimes - * The number of times to do the action. + * The number of times to do the action. * * @param cons - * The action to perform. + * The action to perform. */ public static void doTimes(final int nTimes, final Consumer cons) { for (int i = 0; i < nTimes; i++) { @@ -56,36 +53,37 @@ public class FuncUtils { * Return an operator that executes until it converges. * * @param op - * The operator to execute. + * The operator to execute. * * @param maxTries - * The maximum amount of times to apply the function in - * an attempt to cause it to converge. - * + * The maximum amount of times to apply the function in an + * attempt to cause it to converge. + * * @return The requested operator. */ - public static UnaryOperator converge(final UnaryOperator op, final int maxTries) { - return converge(op, (nw, old) -> nw.equals(old), maxTries); + public static UnaryOperator converge(final UnaryOperator op, + final int maxTries) { + return converge(op, Object::equals, maxTries); } /** * Return an operator that executes until it converges. * * @param op - * The operator to execute. + * The operator to execute. * @param converged - * The predicate to execute to check if the function has - * converged. + * The predicate to execute to check if the function has + * converged. * * @param maxTries - * The maximum amount of times to apply the function in - * an attempt to cause it to converge. - * + * The maximum amount of times to apply the function in an + * attempt to cause it to converge. + * * @return The requested operator. */ - public static UnaryOperator converge(final UnaryOperator op, final BiPredicate converged, - final int maxTries) { - return (val) -> { + public static UnaryOperator converge(final UnaryOperator op, + final BiPredicate converged, final int maxTries) { + return val -> { T newVal = op.apply(val); T oldVal; -- cgit v1.2.3