From fefd6eb2917b9a0856c247353545cc13876b6eda Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Tue, 1 Dec 2020 20:19:34 -0500 Subject: An assortment of changes/new things --- .../main/java/bjc/utils/funcutils/Callables.java | 60 ++++++++++++ .../java/bjc/utils/funcutils/ChainIterator.java | 54 +++++++++++ .../main/java/bjc/utils/funcutils/FuncUtils.java | 34 ++++--- .../main/java/bjc/utils/funcutils/Isomorphism.java | 59 ------------ .../java/bjc/utils/funcutils/IteratorUtils.java | 102 ++++++++++----------- .../bjc/utils/funcutils/QueueBackedIterator.java | 36 ++++++++ .../main/java/bjc/utils/funcutils/Strategy.java | 81 ++++++++++++++++ 7 files changed, 304 insertions(+), 122 deletions(-) create mode 100644 base/src/main/java/bjc/utils/funcutils/Callables.java create mode 100644 base/src/main/java/bjc/utils/funcutils/ChainIterator.java delete mode 100644 base/src/main/java/bjc/utils/funcutils/Isomorphism.java create mode 100644 base/src/main/java/bjc/utils/funcutils/QueueBackedIterator.java create mode 100644 base/src/main/java/bjc/utils/funcutils/Strategy.java (limited to 'base/src/main/java/bjc/utils/funcutils') diff --git a/base/src/main/java/bjc/utils/funcutils/Callables.java b/base/src/main/java/bjc/utils/funcutils/Callables.java new file mode 100644 index 0000000..5895347 --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/Callables.java @@ -0,0 +1,60 @@ +package bjc.utils.funcutils; + +import java.util.concurrent.*; +import java.util.function.*; + +/** + * Utility function for dealing with callables and other things. + * + * @author Ben Culkin + * + */ +public class Callables +{ + /** + * Perform a 'bind' that appends a function to a callable. + * + * @param The type originally returned by the callable. + * @param The type returned by the function. + * + * @param call The original callable. + * @param func The function to use to transform the result. + * + * @return A callable which applies the given function to the result of them. + */ + public static Callable bind( + Callable call, Function> func) + { + return () -> func.apply(call.call()).call(); + } + + /** + * Convert a normal function to a function on callables. + * + * @param The input to the function. + * @param The output from the function. + * + * @param func The function to convert. + * + * @return The function, made to work over callables. + */ + public static Function, Callable> + fmap(Function func) + { + return (inp) -> () -> func.apply(inp.call()); + } + + /** + * Convert a future into a callable. + * + * @param The type returned by the future. + * + * @param fut The future to convert. + * + * @return A future which yields that value. + */ + public static Callable obtain(Future fut) + { + return () -> fut.get(); + } +} diff --git a/base/src/main/java/bjc/utils/funcutils/ChainIterator.java b/base/src/main/java/bjc/utils/funcutils/ChainIterator.java new file mode 100644 index 0000000..36f94e5 --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/ChainIterator.java @@ -0,0 +1,54 @@ +package bjc.utils.funcutils; + +import java.util.*; +import java.util.function.*; + +/** + * A chain iterator. This is essentially flatMap in iterator form. + * + * @author bjculkin + * + * @param + * The type of the input values. + * + * @param + * The type of the output values. + */ +public class ChainIterator implements Iterator { + private Iterator mainItr; + private Function> trans; + + private Iterator curItr; + + /** + * Create a new chain iterator. + * + * @param mainItr + * The main iterator for input. + * + * @param trans + * The transformation to use to produce the outputs. + */ + public ChainIterator(Iterator mainItr, Function> trans) { + this.mainItr = mainItr; + this.trans = trans; + } + + @Override + public boolean hasNext() { + if (curItr != null) { + return curItr.hasNext() ? true : mainItr.hasNext(); + } + + return mainItr.hasNext(); + } + + @Override + public T2 next() { + if (curItr == null || !curItr.hasNext()) { + curItr = trans.apply(mainItr.next()); + } + + return curItr.next(); + } +} \ No newline at end of file diff --git a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java index 70e521a..2c65876 100644 --- a/base/src/main/java/bjc/utils/funcutils/FuncUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/FuncUtils.java @@ -29,9 +29,12 @@ public class FuncUtils { * * @return The function transformed into a unary function returning a function. */ - public static Function> - curry2(final BiFunction func) { - return arg1 -> arg2 -> func.apply(arg1, arg2); + public static Function> curry2( + final BiFunction func) + { + return arg1 -> + arg2 -> + func.apply(arg1, arg2); } /** @@ -43,14 +46,17 @@ public class FuncUtils { * @param cons * The action to perform. */ - public static void doTimes(final int nTimes, final Consumer cons) { - for (int i = 0; i < nTimes; i++) { - cons.accept(i); - } + public static void doTimes( + final int nTimes, + final Consumer cons) + { + for (int i = 0; i < nTimes; i++) cons.accept(i); } /** * Return an operator that executes until it converges. + * + * @param The type the operator is on. * * @param op * The operator to execute. @@ -62,12 +68,15 @@ public class FuncUtils { * @return The requested operator. */ public static UnaryOperator converge(final UnaryOperator op, - final int maxTries) { + final int maxTries) + { return converge(op, Object::equals, maxTries); } /** * Return an operator that executes until it converges. + * + * @param The type the operator is on. * * @param op * The operator to execute. @@ -81,11 +90,14 @@ public class FuncUtils { * * @return The requested operator. */ - public static UnaryOperator converge(final UnaryOperator op, - final BiPredicate converged, final int maxTries) { + public static UnaryOperator converge( + final UnaryOperator op, + final BiPredicate converged, + final int maxTries) + { return val -> { T newVal = op.apply(val); - T oldVal; + T oldVal = newVal; int tries = 0; diff --git a/base/src/main/java/bjc/utils/funcutils/Isomorphism.java b/base/src/main/java/bjc/utils/funcutils/Isomorphism.java deleted file mode 100644 index c219d7f..0000000 --- a/base/src/main/java/bjc/utils/funcutils/Isomorphism.java +++ /dev/null @@ -1,59 +0,0 @@ -package bjc.utils.funcutils; - -import java.util.function.Function; - -/** - * A pair of functions to transform between a pair of types. - * - * @author bjculkin - * - * @param - * The source type of the isomorphism. - * - * @param - * The destination type of isomorphism. - */ -public class Isomorphism { - /* The function to the destination type. */ - private Function toFunc; - /* The function to the source type. */ - private Function fromFunc; - - /** - * Create a new isomorphism. - * - * @param to - * The 'forward' function, from the source to the definition. - * - * @param from - * The 'backward' function, from the definition to the source. - */ - public Isomorphism(Function to, Function from) { - toFunc = to; - fromFunc = from; - } - - /** - * Apply the isomorphism forward. - * - * @param val - * The source value. - * - * @return The destination value. - */ - public D to(S val) { - return toFunc.apply(val); - } - - /** - * Apply the isomorphism backward. - * - * @param val - * The destination value. - * - * @return The source value. - */ - public S from(D val) { - return fromFunc.apply(val); - } -} diff --git a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java index 8d51996..ea67295 100644 --- a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java @@ -3,7 +3,7 @@ package bjc.utils.funcutils; import java.util.*; import java.util.function.*; -import bjc.data.ArrayIterator; +import bjc.data.*; /** * Utility methods for dealing with iterators. @@ -12,58 +12,10 @@ import bjc.data.ArrayIterator; * */ public class IteratorUtils { - /** - * A chain iterator. This is essentially flatMap in iterator form. - * - * @author bjculkin - * - * @param - * The type of the input values. - * - * @param - * The type of the output values. - */ - public static class ChainIterator implements Iterator { - private Iterator mainItr; - private Function> trans; - - private Iterator curItr; - - /** - * Create a new chain iterator. - * - * @param mainItr - * The main iterator for input. - * - * @param trans - * The transformation to use to produce the outputs. - */ - public ChainIterator(Iterator mainItr, Function> trans) { - this.mainItr = mainItr; - this.trans = trans; - } - - @Override - public boolean hasNext() { - if (curItr != null) { - return curItr.hasNext() ? true : mainItr.hasNext(); - } - - return mainItr.hasNext(); - } - - @Override - public T2 next() { - if (curItr == null || !curItr.hasNext()) { - curItr = trans.apply(mainItr.next()); - } - - return curItr.next(); - } - } - /** * Convert an iterator to an iterable. + * + * @param The type being iterated over. * * @param itr * The iterator to convert. @@ -77,6 +29,8 @@ public class IteratorUtils { /** * Convert an iterable to an iterator. * + * @param The type being iterated over. + * * @param itr * The iterable to convert. * @@ -89,18 +43,23 @@ public class IteratorUtils { /** * Convert an array to an iterator. * + * @param The type being iterated over. + * * @param parms * The array to iterate over. * * @return An iterator over the provided array. */ @SafeVarargs - public static Iterator AI(E... parms) { + public static Iterator I(E... parms) { return new ArrayIterator<>(parms); } /** * Create a chain iterator. + * + * @param The initial type being iterated over. + * @param The resulting type being iterated over. * * @param itrA * The iterator for input values. @@ -114,4 +73,43 @@ public class IteratorUtils { Function> itrB) { return new ChainIterator<>(itrA, itrB); } + + /** + * Perform a left-fold over an iterator. + * + * @param The type of elements in the iterator. + * @param The result from the fold. + * + * @param itr The items to iterate over. + * @param zero The initial element for the fold. + * @param folder The function that does the folding. + * + * @return The result of folding over the iterator. + */ + public static ResultType foldLeft( + Iterable itr, + ResultType zero, + BiFunction folder) + { + ResultType state = zero; + for (ElementType elem : itr) { + state = folder.apply(elem, state); + } + return state; + } + + /** + * Creates an 'entangled' pair of a consumer and an iterator. + * + * @param The type of value involved. + * + * @return A pair consisting of a consumer of values, and an iterator that + * yields the consumed values. + */ + public static + IPair, Iterator> entangle() + { + Queue backer = new ArrayDeque<>(); + return IPair.pair(backer::add, new QueueBackedIterator<>(backer)); + } } diff --git a/base/src/main/java/bjc/utils/funcutils/QueueBackedIterator.java b/base/src/main/java/bjc/utils/funcutils/QueueBackedIterator.java new file mode 100644 index 0000000..8b9f401 --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/QueueBackedIterator.java @@ -0,0 +1,36 @@ +package bjc.utils.funcutils; + +import java.util.*; + +/** + * An iterator backed by a queue. + * + * @author Ben Culkin + * + * @param The type of element + */ +public class QueueBackedIterator + implements Iterator +{ + private final Queue backer; + + /** + * Create a new queue-backed iterator. + * + * @param backer The queue which backs this iterator. + */ + public QueueBackedIterator(Queue backer) + { + this.backer = backer; + } + + @Override + public boolean hasNext() { + return !backer.isEmpty(); + } + + @Override + public ElementType next() { + return backer.remove(); + } +} \ No newline at end of file diff --git a/base/src/main/java/bjc/utils/funcutils/Strategy.java b/base/src/main/java/bjc/utils/funcutils/Strategy.java new file mode 100644 index 0000000..316879f --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/Strategy.java @@ -0,0 +1,81 @@ +package bjc.utils.funcutils; + +import java.util.concurrent.*; +import java.util.function.*; + +/** + * Strategy for dealing with parallel execution. + * + * @author Ben Culkin + * + * @param The type returned by the tasks. + * + */ +public interface Strategy extends Function, Future> +{ + /** + * Convert a function into one which operates concurrently, using this strategy. + * + * @param The type of the function argument. + * + * @param func The type of the function. + * + * @return A function which executes concurrently. + */ + public default Function> using(Function func) + { + return (input) -> this.apply(() -> func.apply(input)); + } + + /** + * A strategy which will run tasks in serial. + * + * @param The type returned by the task. + * + * @return A strategy which executes things serially. + */ + public static Strategy serial() + { + return (call) -> { + FutureTask task = new FutureTask<>(call); + task.run(); + return task; + }; + } + /** + * A strategy which creates a fresh thread to execute a task on. + * + * @param The type returned by the task. + * + * @return A strategy which uses threads to create tasks. + */ + public static Strategy simpleThread() + { + // I leave this as an example as of what is possible with combinators. + // return (call) -> invoke(introducing( + // () -> new FutureTask<>(call), + // (task, input) -> doWith( + // (FutureTask tsk) -> + // new Thread(task).start()).apply(task) + // )); + return (call) -> { + FutureTask task = new FutureTask<>(call); + new Thread(task).start(); + return task; + }; + } + + /** + * A strategy that uses an executor service. + * + * @param The type returned by the task. + * + * @param svc The executor service to use. + * + * @return A strategy which uses the provided executor. + */ + public static Strategy executorService(ExecutorService svc) + { + return svc::submit; + } +} -- cgit v1.2.3 From a2c7425458f645802a352abc4783e0afc73dba13 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 3 Dec 2020 19:22:35 -0500 Subject: Adapt to esodata changes --- .../java/bjc/utils/funcutils/CollectorUtils.java | 8 ++--- .../bjc/utils/funcutils/CompoundCollector.java | 22 ++++++------- .../main/java/bjc/utils/funcutils/EnumUtils.java | 4 +-- .../java/bjc/utils/funcutils/IteratorUtils.java | 4 +-- .../main/java/bjc/utils/funcutils/ListUtils.java | 38 +++++++++++----------- .../main/java/bjc/utils/funcutils/TreeUtils.java | 22 ++++++------- 6 files changed, 49 insertions(+), 49 deletions(-) (limited to 'base/src/main/java/bjc/utils/funcutils') diff --git a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java index 81313c8..a92c2d1 100644 --- a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java @@ -2,8 +2,8 @@ package bjc.utils.funcutils; import java.util.stream.Collector; -import bjc.data.IHolder; -import bjc.data.IPair; +import bjc.data.Holder; +import bjc.data.Pair; /** * Utilities for producing implementations of {@link Collector} @@ -38,8 +38,8 @@ public class CollectorUtils { * @return A collector that functions as mentioned above. */ public static - Collector>, - IPair> + Collector>, + Pair> compoundCollect(final Collector first, final Collector second) { return new CompoundCollector<>(first, second); diff --git a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java index 5e51c20..5aa266e 100644 --- a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java +++ b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java @@ -7,10 +7,10 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; -import bjc.data.IHolder; -import bjc.data.IPair; -import bjc.data.Identity; +import bjc.data.Holder; import bjc.data.Pair; +import bjc.data.Identity; +import bjc.data.SimplePair; /** * Implementation of a collecter that uses two collectors. @@ -18,8 +18,8 @@ import bjc.data.Pair; * @author Ben Culkin */ final class CompoundCollector - implements Collector>, - IPair> { + implements Collector>, + Pair> { /* Our characteristics. */ private final Set characteristicSet; @@ -48,7 +48,7 @@ final class CompoundCollector>, InitialType> accumulator() { + public BiConsumer>, InitialType> accumulator() { final BiConsumer firstAccumulator = first.accumulator(); final BiConsumer secondAccumulator = second.accumulator(); @@ -68,7 +68,7 @@ final class CompoundCollector>> combiner() { + public BinaryOperator>> combiner() { final BinaryOperator firstCombiner = first.combiner(); final BinaryOperator secondCombiner = second.combiner(); @@ -80,25 +80,25 @@ final class CompoundCollector>, IPair> + public Function>, Pair> finisher() { return state -> state.unwrap(pair -> { return pair.bind((left, right) -> { final FinalType1 finalLeft = first.finisher().apply(left); final FinalType2 finalRight = second.finisher().apply(right); - return new Pair<>(finalLeft, finalRight); + return new SimplePair<>(finalLeft, finalRight); }); }); } @Override - public Supplier>> supplier() { + public Supplier>> supplier() { return () -> { final AuxType1 initialLeft = first.supplier().get(); final AuxType2 initialRight = second.supplier().get(); - return new Identity<>(new Pair<>(initialLeft, initialRight)); + return new Identity<>(new SimplePair<>(initialLeft, initialRight)); }; } } diff --git a/base/src/main/java/bjc/utils/funcutils/EnumUtils.java b/base/src/main/java/bjc/utils/funcutils/EnumUtils.java index e8898ca..6d53952 100644 --- a/base/src/main/java/bjc/utils/funcutils/EnumUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/EnumUtils.java @@ -4,7 +4,7 @@ import java.util.Random; import java.util.function.Consumer; import bjc.funcdata.FunctionalList; -import bjc.funcdata.IList; +import bjc.funcdata.ListEx; /** * Utility methods on enums. @@ -34,7 +34,7 @@ public class EnumUtils { final int nValues, final Consumer action, final Random rnd) { final E[] enumValues = clasz.getEnumConstants(); - final IList valueList = new FunctionalList<>(enumValues); + final ListEx valueList = new FunctionalList<>(enumValues); final int randomValueCount = enumValues.length - nValues; diff --git a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java index ea67295..662b1bf 100644 --- a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java @@ -107,9 +107,9 @@ public class IteratorUtils { * yields the consumed values. */ public static - IPair, Iterator> entangle() + Pair, Iterator> entangle() { Queue backer = new ArrayDeque<>(); - return IPair.pair(backer::add, new QueueBackedIterator<>(backer)); + return Pair.pair(backer::add, new QueueBackedIterator<>(backer)); } } diff --git a/base/src/main/java/bjc/utils/funcutils/ListUtils.java b/base/src/main/java/bjc/utils/funcutils/ListUtils.java index e3662af..17642ce 100644 --- a/base/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.function.*; import bjc.funcdata.FunctionalList; -import bjc.funcdata.IList; +import bjc.funcdata.ListEx; /** * Utilities for manipulating FunctionalLists and regular Collections lists that @@ -27,7 +27,7 @@ public class ListUtils { * * @return The collapsed string of tokens. */ - public static String collapseTokens(final IList input) { + public static String collapseTokens(final ListEx input) { if (input == null) throw new NullPointerException("Input must not be null"); return collapseTokens(input, ""); @@ -45,7 +45,7 @@ public class ListUtils { * * @return The collapsed string of tokens. */ - public static String collapseTokens(final IList input, + public static String collapseTokens(final ListEx input, final String seperator) { if (input == null) throw new NullPointerException("Input must not be null"); else if (seperator == null) throw new NullPointerException("Seperator must not be null"); @@ -89,9 +89,9 @@ public class ListUtils { * @return A new list containing the desired number of items randomly selected * from the specified list without replacement. */ - public static IList drawWithoutReplacement(final IList list, + public static ListEx drawWithoutReplacement(final ListEx list, final int number, final Function rng) { - final IList selected = new FunctionalList<>(new ArrayList<>(number)); + final ListEx selected = new FunctionalList<>(new ArrayList<>(number)); final int total = list.getSize(); @@ -133,9 +133,9 @@ public class ListUtils { * @return A new list containing the desired number of items randomly selected * from the specified list. */ - public static IList drawWithReplacement(final IList list, final int number, + public static ListEx drawWithReplacement(final ListEx list, final int number, final Function rng) { - final IList selected = new FunctionalList<>(new ArrayList<>(number)); + final ListEx selected = new FunctionalList<>(new ArrayList<>(number)); for (int i = 0; i < number; i++) selected.add(list.randItem(rng)); @@ -161,7 +161,7 @@ public class ListUtils { * * @return A list partitioned according to the above rules. */ - public static IList> groupPartition(final IList input, + public static ListEx> groupPartition(final ListEx input, final Function counter, final int partitionSize) { if (input == null) { throw new NullPointerException("Input list must not be null"); @@ -176,10 +176,10 @@ public class ListUtils { } /* List that holds our results. */ - final IList> returned = new FunctionalList<>(); + final ListEx> returned = new FunctionalList<>(); /* List that holds elements rejected during current pass. */ - final IList rejected = new FunctionalList<>(); + final ListEx rejected = new FunctionalList<>(); final GroupPartIteration it = new GroupPartIteration<>(returned, rejected, partitionSize, counter); @@ -215,10 +215,10 @@ public class ListUtils { * @return A list containing all the elements of the lists. */ @SafeVarargs - public static IList mergeLists(final IList... lists) { - final IList returned = new FunctionalList<>(); + public static ListEx mergeLists(final ListEx... lists) { + final ListEx returned = new FunctionalList<>(); - for (final IList list : lists) { + for (final ListEx list : lists) { for (final E itm : list.toIterable()) returned.add(itm); } @@ -249,12 +249,12 @@ public class ListUtils { * If the list couldn't be padded to the * desired size. */ - public static IList padList(final IList list, + public static ListEx padList(final ListEx list, final Function counter, final int size, final Supplier padder) { int count = 0; - final IList returned = new FunctionalList<>(); + final ListEx returned = new FunctionalList<>(); for (final E itm : list.toIterable()) { count += counter.apply(itm); @@ -433,12 +433,12 @@ public class ListUtils { */ class GroupPartIteration implements Consumer { /* The list we're returning. */ - private final IList> returnedList; + private final ListEx> returnedList; /* The current partition of the list. */ - public IList currentPartition; + public ListEx currentPartition; /* The items rejected from the current partition. */ - private final IList rejectedItems; + private final ListEx rejectedItems; /* The number of items in the current partition. */ private int numberInCurrentPartition; @@ -465,7 +465,7 @@ class GroupPartIteration implements Consumer { * @param eleCount * The function to use to determine the value of an item. */ - public GroupPartIteration(final IList> returned, final IList rejects, + public GroupPartIteration(final ListEx> returned, final ListEx rejects, final int nPerPart, final Function eleCount) { this.returnedList = returned; this.rejectedItems = rejects; diff --git a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java index 59f60a2..41a01d8 100644 --- a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java @@ -21,8 +21,8 @@ public class TreeUtils { * The path to mark nodes with. * @return The list of marked paths. */ - public static IList> outlineTree(ITree tre, Predicate leafMarker) { - IList> paths = new FunctionalList<>(); + public static ListEx> outlineTree(Tree tre, Predicate leafMarker) { + ListEx> paths = new FunctionalList<>(); LinkedList path = new LinkedList<>(); path.add(tre.getHead()); @@ -33,11 +33,11 @@ public class TreeUtils { } /* Find a path in a tree. */ - private static void findPath(ITree subtree, LinkedList path, - Predicate leafMarker, IList> paths) { + private static void findPath(Tree subtree, LinkedList path, + Predicate leafMarker, ListEx> paths) { if (subtree.getChildrenCount() == 0 && leafMarker.test(subtree.getHead())) { /* We're at a matching leaf node. Add it. */ - IList finalPath = new FunctionalList<>(); + ListEx finalPath = new FunctionalList<>(); for (T ePath : path) finalPath.add(ePath); @@ -63,10 +63,10 @@ public class TreeUtils { * @param expander The function to expand nodes. * @return A transformed copy of the tree. */ - public static ITree substitute( - ITree tree, + public static Tree substitute( + Tree tree, Predicate marker, - Function> expander) { + Function> expander) { tree.topDownTransform((contents) -> { if (marker.test(contents)) return TopDownTransformResult.TRANSFORM; else return TopDownTransformResult.PASSTHROUGH; @@ -84,9 +84,9 @@ public class TreeUtils { * @param environment A map which contains the variables to substitute. * @return A transformed copy of the tree. */ - public static ITree substitute( - ITree tree, - IMap> environment) { + public static Tree substitute( + Tree tree, + MapEx> environment) { return substitute( tree, environment::containsKey, -- cgit v1.2.3 From f3814a84f8471684cd483347db4fb7b107c2e635 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 3 Dec 2020 19:28:15 -0500 Subject: Rename interfaces to match Java style Rename several interfaces that were in the style IWhatever, which Java doesn't use --- .../src/main/java/bjc/utils/funcutils/Builder.java | 34 ++++++++++++++++++++++ .../main/java/bjc/utils/funcutils/IBuilder.java | 34 ---------------------- 2 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 base/src/main/java/bjc/utils/funcutils/Builder.java delete mode 100644 base/src/main/java/bjc/utils/funcutils/IBuilder.java (limited to 'base/src/main/java/bjc/utils/funcutils') diff --git a/base/src/main/java/bjc/utils/funcutils/Builder.java b/base/src/main/java/bjc/utils/funcutils/Builder.java new file mode 100644 index 0000000..72c045d --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/Builder.java @@ -0,0 +1,34 @@ +package bjc.utils.funcutils; + +/** + * Generic interface for objects that implement the builder pattern. + * + * @author ben + * + * @param + * The type of object being built. + */ +public interface Builder { + /** + * Build the object this builder is building. + * + * @return The built object. + * + * @throws IllegalStateException + * If the data in the builder cannot be built into + * its corresponding object at this point in time. + */ + public E build(); + + /** + * Reset the state of this builder to its initial state. + * + * @throws UnsupportedOperationException + * If the builder doesn't support + * resetting its state. + */ + public default void reset() { + throw new UnsupportedOperationException( + "Builder doesn't support state resetting"); + } +} diff --git a/base/src/main/java/bjc/utils/funcutils/IBuilder.java b/base/src/main/java/bjc/utils/funcutils/IBuilder.java deleted file mode 100644 index b1a2020..0000000 --- a/base/src/main/java/bjc/utils/funcutils/IBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -package bjc.utils.funcutils; - -/** - * Generic interface for objects that implement the builder pattern. - * - * @author ben - * - * @param - * The type of object being built. - */ -public interface IBuilder { - /** - * Build the object this builder is building. - * - * @return The built object. - * - * @throws IllegalStateException - * If the data in the builder cannot be built into - * its corresponding object at this point in time. - */ - public E build(); - - /** - * Reset the state of this builder to its initial state. - * - * @throws UnsupportedOperationException - * If the builder doesn't support - * resetting its state. - */ - public default void reset() { - throw new UnsupportedOperationException( - "Builder doesn't support state resetting"); - } -} -- cgit v1.2.3