From 69a769bc6474d71f5108af0698dd5454319e2a6c Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 25 Jun 2023 15:09:13 -0400 Subject: Fix a few warnings --- .../main/java/bjc/utils/funcutils/StringUtils.java | 6 +- .../main/java/bjc/utils/funcutils/TreeUtils.java | 73 +++++++++++----------- 2 files changed, 39 insertions(+), 40 deletions(-) (limited to 'base/src/main/java/bjc/utils/funcutils') diff --git a/base/src/main/java/bjc/utils/funcutils/StringUtils.java b/base/src/main/java/bjc/utils/funcutils/StringUtils.java index 2d86083..7551cb3 100644 --- a/base/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -129,8 +129,7 @@ public class StringUtils { * @return The sequence as an English list. */ public static String toEnglishList(final Object[] objects, final boolean and) { - if (and) return toEnglishList(objects, "and"); - else return toEnglishList(objects, "or"); + return and ? toEnglishList(objects, "and") : toEnglishList(objects, "or"); } /** Count the number of graphemes in a string. @@ -190,8 +189,7 @@ public class StringUtils { int idx = strang.indexOf(until); if (idx == -1) { - if (allowFail) return strang; - else return null; + return allowFail ? strang : null; } return strang.substring(0, strang.indexOf(until)); diff --git a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java index daab8a1..22c4d3c 100644 --- a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java @@ -6,18 +6,22 @@ import java.util.function.*; import bjc.data.*; import bjc.funcdata.*; -/** Implements various utilities for trees. +/** + * Implements various utilities for trees. * - * @author Benjamin Culkin */ + * @author Benjamin Culkin + */ public class TreeUtils { - /** Convert a tree into a list of outline nodes that match a certain path. + /** + * Convert a tree into a list of outline nodes that match a certain path. * - * @param The type contained in the tree. + * @param The type contained in the tree. * - * @param tre The tree to outline. + * @param tre The tree to outline. * @param leafMarker The path to mark nodes with. * - * @return The list of marked paths. */ + * @return The list of marked paths. + */ public static ListEx> outlineTree(Tree tre, Predicate leafMarker) { ListEx> paths = new FunctionalList<>(); @@ -30,13 +34,14 @@ public class TreeUtils { } /* Find a path in a tree. */ - private static void findPath(Tree subtree, LinkedList path, - Predicate leafMarker, ListEx> 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. */ ListEx finalPath = new FunctionalList<>(); - for (T ePath : path) finalPath.add(ePath); + for (T ePath : path) + finalPath.add(ePath); finalPath.add(subtree.getHead()); @@ -50,43 +55,39 @@ public class TreeUtils { path.removeLast(); } } - - /** Performs 'variable substitution' or something along those lines on a tree. + + /** + * Performs 'variable substitution' or something along those lines on a tree. * * @param The type of element contained in the tree. * - * @param tree The tree to do expansion in. - * @param marker The function to mark which nodes should be expanded. - * @param expander The function to expand nodes. + * @param tree The tree to do expansion in. + * @param marker The function to mark which nodes should be expanded. + * @param expander The function to expand nodes. * - * @return A transformed copy of the tree. */ - public static Tree substitute( - Tree tree, - Predicate marker, - Function> expander) { - tree.topDownTransform((contents) -> { - if (marker.test(contents)) return TopDownTransformResult.TRANSFORM; - else return TopDownTransformResult.PASSTHROUGH; - }, (node) -> { - return expander.apply(node.getHead()); - }); + * @return A transformed copy of the tree. + */ + public static Tree substitute(Tree tree, + Predicate marker, Function> expander) { + Function picker = (contents) -> marker.test(contents) ? TopDownTransformResult.TRANSFORM + : TopDownTransformResult.PASSTHROUGH; + tree.topDownTransform(picker, (node) -> expander.apply(node.getHead())); return tree; } - - /** Performs 'variable substitution' or something along those lines on a tree. + + /** + * Performs 'variable substitution' or something along those lines on a tree. * * @param The type of element contained in the tree. * - * @param tree The tree to do expansion in. - * @param environment A map which contains the variables to substitute. + * @param tree The tree to do expansion in. + * @param environment A map which contains the variables to substitute. * - * @return A transformed copy of the tree. */ - public static Tree substitute( - Tree tree, + * @return A transformed copy of the tree. + */ + public static Tree substitute(Tree tree, MapEx> environment) { - return substitute( - tree, - environment::containsKey, - (element) -> environment.get(element).get()); + return substitute(tree, environment::containsKey, (element) -> environment.get(element).get()); } } -- cgit v1.2.3