From f7a10e0e57d6f0ea83643c3d5763ff405af73337 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 28 Sep 2016 13:44:04 -0400 Subject: Formatting pass --- BJC-Utils2/.classpath | 6 +- BJC-Utils2/pom.xml | 13 +++- .../utils/examples/parsing/TreeConstructTest.java | 3 +- .../utils/components/FileComponentRepository.java | 40 +++++------ .../bjc/utils/components/IComponentRepository.java | 3 +- .../src/main/java/bjc/utils/data/BoundLazy.java | 9 ++- .../main/java/bjc/utils/data/BoundLazyPair.java | 31 +++++---- .../src/main/java/bjc/utils/data/Either.java | 25 ++++--- .../java/bjc/utils/data/HalfBoundLazyPair.java | 18 +++-- .../src/main/java/bjc/utils/data/IHolder.java | 6 +- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 35 ++++++---- BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java | 9 ++- .../src/main/java/bjc/utils/data/LazyPair.java | 14 ++-- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 14 ++-- .../main/java/bjc/utils/funcdata/ExtendedMap.java | 10 +-- .../java/bjc/utils/funcdata/FunctionalList.java | 5 +- .../java/bjc/utils/funcdata/FunctionalMap.java | 10 +-- .../src/main/java/bjc/utils/funcdata/IList.java | 11 +-- .../src/main/java/bjc/utils/funcdata/IMap.java | 30 ++++----- .../src/main/java/bjc/utils/funcdata/ITree.java | 6 +- .../bjc/utils/funcdata/TransformedValueMap.java | 10 +-- .../src/main/java/bjc/utils/funcdata/Tree.java | 23 ++++--- .../utils/funcdata/bst/BinarySearchTreeNode.java | 3 +- .../java/bjc/utils/funcdata/theory/Bifunctor.java | 48 ++++++++----- .../java/bjc/utils/funcdata/theory/Functor.java | 6 +- .../java/bjc/utils/funcutils/CollectorUtils.java | 11 ++- .../bjc/utils/funcutils/CompoundCollector.java | 31 +++++---- .../main/java/bjc/utils/funcutils/ListUtils.java | 78 +++++++++++----------- .../main/java/bjc/utils/funcutils/NumberUtils.java | 4 +- .../main/java/bjc/utils/funcutils/StringUtils.java | 4 +- .../main/java/bjc/utils/gen/WeightedGrammar.java | 9 ++- .../java/bjc/utils/gui/SimpleInternalDialogs.java | 4 +- .../java/bjc/utils/gui/TextAreaOutputStream.java | 20 +++--- .../bjc/utils/gui/panels/ListParameterPanel.java | 8 +-- .../java/bjc/utils/gui/panels/SimpleListPanel.java | 30 ++++----- .../utils/parserutils/RuleBasedConfigReader.java | 19 ++++-- .../utils/parserutils/RuleBasedReaderPragmas.java | 10 +-- .../bjc/utils/parserutils/TokenTransformer.java | 27 +++++--- .../bjc/utils/parserutils/TreeConstructor.java | 8 ++- 39 files changed, 385 insertions(+), 266 deletions(-) (limited to 'BJC-Utils2') diff --git a/BJC-Utils2/.classpath b/BJC-Utils2/.classpath index 16e7185..17c9f20 100644 --- a/BJC-Utils2/.classpath +++ b/BJC-Utils2/.classpath @@ -18,6 +18,10 @@ - + + + + + diff --git a/BJC-Utils2/pom.xml b/BJC-Utils2/pom.xml index 1a57d4c..da5e9e9 100644 --- a/BJC-Utils2/pom.xml +++ b/BJC-Utils2/pom.xml @@ -2,6 +2,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + + bjc BJC-Utils2 0.1.0-SNAPSHOT @@ -12,7 +24,6 @@ UTF-8 - 1.8 diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java index 0be55ea..edf3332 100644 --- a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java +++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java @@ -105,7 +105,8 @@ public class TreeConstructTest { return false; }; - IMap>, ITree>> operators = new FunctionalMap<>(); + IMap>, + ITree>> operators = new FunctionalMap<>(); operators.put("[", (queuedTrees) -> { return null; diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java index bb2d421..6c1bb71 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -25,7 +25,8 @@ import bjc.utils.funcutils.FileUtils; * @param * The type of component being read in */ -public class FileComponentRepository +public class FileComponentRepository< + ComponentType extends IDescribedComponent> implements IComponentRepository { // The logger to use for storing data about this class private static final Logger CLASS_LOGGER = Logger @@ -71,24 +72,25 @@ public class FileComponentRepository // Predicate to use to traverse all the files in a directory, but // not recurse into sub-directories - BiPredicate firstLevelTraverser = (pth, - attr) -> { - if (attr.isDirectory() && !isFirstDir.getValue()) { - - /* - * Skip directories, they probably have component support - * files. - */ - return false; - } - - /* - * Don't skip the first directory, that's the parent directory - */ - isFirstDir.replace(false); - - return true; - }; + BiPredicate firstLevelTraverser = (pth, attr) -> { + if (attr.isDirectory() && !isFirstDir.getValue()) { + + /* + * Skip directories, they probably have component + * support files. + */ + return false; + } + + /* + * Don't skip the first directory, that's the parent + * directory + */ + isFirstDir.replace(false); + + return true; + }; // Try reading components try { diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java index 1d322af..a4dbfde 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java @@ -12,7 +12,8 @@ import bjc.utils.funcdata.IMap; * @param * The type of components contained in this repository */ -public interface IComponentRepository { +public interface IComponentRepository< + ComponentType extends IDescribedComponent> { /** * Get all of the components this repository knows about * diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java index b6cd715..d6f3b1d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java @@ -35,7 +35,8 @@ class BoundLazy /* * Transformations currently pending on the bound value */ - private IList> actions = new FunctionalList<>(); + private IList> actions = new FunctionalList<>(); /* * Create a new bound lazy value @@ -52,7 +53,8 @@ class BoundLazy /* * Prepare a list of pending actions */ - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); /* @@ -91,7 +93,8 @@ class BoundLazy public IHolder map( Function mapper) { // Prepare a list of pending actions - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); // Prepare the new supplier diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java index c527d94..622bd2e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java @@ -6,18 +6,21 @@ import java.util.function.Supplier; class BoundLazyPair implements IPair { - private Supplier leftSupplier; - private Supplier rightSupplier; + private Supplier< + OldLeft> leftSupplier; + private Supplier< + OldRight> rightSupplier; private BiFunction> binder; - private IPair boundPair; + private IPair boundPair; private boolean pairBound; public BoundLazyPair(Supplier leftSupp, - Supplier rightSupp, - BiFunction> bindr) { + Supplier rightSupp, BiFunction> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; binder = bindr; @@ -25,9 +28,10 @@ class BoundLazyPair @Override public IPair bind( - BiFunction> bindr) { - IHolder> newPair = new Identity<>( - boundPair); + BiFunction> bindr) { + IHolder> newPair = new Identity<>(boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { @@ -90,10 +94,13 @@ class BoundLazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java index 9418882..aa38959 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java @@ -26,10 +26,12 @@ public class Either * The value to put on the left * @return An either with the left side occupied */ - public static Either fromLeft( - LeftType left) { + public static Either fromLeft( + LeftType left) { return new Either<>(left, null); } + /** * Create a new either with the right value occupied * @@ -41,8 +43,9 @@ public class Either * The value to put on the right * @return An either with the right side occupied */ - public static Either fromRight( - RightType right) { + public static Either fromRight( + RightType right) { return new Either<>(null, right); } @@ -64,7 +67,8 @@ public class Either @Override public IPair bind( - BiFunction> binder) { + BiFunction> binder) { return binder.apply(leftVal, rightVal); } @@ -89,10 +93,13 @@ public class Either } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { if (isLeft) { return otherPair.bind((otherLeft, otherRight) -> { return new Either<>(leftCombiner.apply(leftVal, otherLeft), diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java index d91ede2..72c0bdf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java @@ -21,9 +21,10 @@ class HalfBoundLazyPair @Override public IPair bind( - BiFunction> bindr) { - IHolder> newPair = new Identity<>( - boundPair); + BiFunction> bindr) { + IHolder> newPair = new Identity<>(boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { @@ -80,10 +81,13 @@ class HalfBoundLazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( 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 b2e4369..a8c9f77 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -43,8 +43,10 @@ public interface IHolder extends Functor { } @Override - default Function, Functor> fmap( - Function func) { + default Function, + Functor> fmap( + Function func) { return (argumentFunctor) -> { if (!(argumentFunctor instanceof IHolder)) { throw new IllegalArgumentException( 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 a2a635f..c82cc8e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -30,7 +30,8 @@ public interface IPair * @return The bound pair */ public IPair bind( - BiFunction> binder); + BiFunction> binder); /** * Bind a function to the left value in this pair @@ -67,8 +68,10 @@ public interface IPair * The pair to combine with * @return The pairs, pairwise combined together */ - public default IPair, IPair> combine( - IPair otherPair) { + public default IPair, + IPair> combine( + IPair otherPair) { return combine(otherPair, (left, otherLeft) -> new Pair<>(left, otherLeft), (right, otherRight) -> new Pair<>(right, otherRight)); @@ -91,10 +94,13 @@ public interface IPair * @param rightCombiner * @return A pair with its values combined */ - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner); + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner); /** * Immediately perfom the specified action with the contents of this @@ -112,22 +118,26 @@ public interface IPair } @Override - default Function, Bifunctor> fmapLeft( - Function func) { + default Function, + Bifunctor> fmapLeft( + Function func) { return (argumentPair) -> { if (!(argumentPair instanceof IPair)) { throw new IllegalArgumentException( "This function can only be applied to instances of IPair"); } - IPair argPair = (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapLeft(func); }; } @Override - default Function, Bifunctor> + default Function< + Bifunctor, Bifunctor> fmapRight(Function func) { return (argumentPair) -> { @@ -136,7 +146,8 @@ public interface IPair "This function can only be applied to instances of IPair"); } - IPair argPair = (IPair) argumentPair; + IPair argPair = (IPair) argumentPair; return argPair.mapRight(func); }; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java index f05204b..ffc4919 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java @@ -18,7 +18,8 @@ import bjc.utils.funcdata.IList; public class Lazy implements IHolder { private Supplier valueSupplier; - private IList> actions = new FunctionalList<>(); + private IList> actions = new FunctionalList<>(); private boolean valueMaterialized; @@ -58,7 +59,8 @@ public class Lazy implements IHolder { @Override public IHolder bind( Function> binder) { - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); @@ -86,7 +88,8 @@ public class Lazy implements IHolder { @Override public IHolder map( Function mapper) { - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java index df4c3ac..53428d9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java @@ -63,7 +63,8 @@ public class LazyPair @Override public IPair bind( - BiFunction> binder) { + BiFunction> binder) { return new BoundLazyPair<>(leftSupplier, rightSupplier, binder); } @@ -96,10 +97,13 @@ public class LazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( 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 1000fc0..3480b2a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -41,7 +41,8 @@ public class Pair @Override public IPair bind( - BiFunction> binder) { + BiFunction> binder) { if (binder == null) { throw new NullPointerException("Binder must not be null."); } @@ -70,10 +71,13 @@ public class Pair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return new Pair<>(leftCombiner.apply(leftValue, otherLeft), rightCombiner.apply(rightValue, otherRight)); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java index 4d50c56..0a2ee39 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java @@ -17,6 +17,11 @@ class ExtendedMap implements IMap { this.store = store; } + @Override + public void clear() { + store.clear(); + } + @Override public boolean containsKey(KeyType key) { if (store.containsKey(key)) { @@ -92,9 +97,4 @@ class ExtendedMap implements IMap { return ListUtils.mergeLists(store.valueList(), delegate.valueList()); } - - @Override - public void clear() { - store.clear(); - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java index 590ed1d..b902207 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -180,9 +180,8 @@ public class FunctionalList implements Cloneable, IList { // Get the iterator for the other list Iterator rightIterator = rightList.toIterable().iterator(); - for (Iterator leftIterator = wrappedList - .iterator(); leftIterator.hasNext() - && rightIterator.hasNext();) { + for (Iterator leftIterator = wrappedList.iterator(); + leftIterator.hasNext() && rightIterator.hasNext();) { // Add the transformed items to the result list E leftVal = leftIterator.next(); T rightVal = rightIterator.next(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java index ce64519..dfe02dc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -60,6 +60,11 @@ public class FunctionalMap wrappedMap = wrap; } + @Override + public void clear() { + wrappedMap.clear(); + } + /* * (non-Javadoc) * @@ -175,9 +180,4 @@ public class FunctionalMap return values; } - - @Override - public void clear() { - wrappedMap.clear(); - } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java index e446b64..47acf1a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -62,8 +62,8 @@ public interface IList { */ public default ReducedType collect( Collector collector) { - BiConsumer accumulator = collector - .accumulator(); + BiConsumer accumulator = collector.accumulator(); return reduceAux(collector.supplier().get(), (value, state) -> { accumulator.accept(state, value); @@ -92,8 +92,8 @@ public interface IList { * @return A new list containing the merged pairs of lists. */ IList combineWith( - IList rightList, - BiFunction itemCombiner); + IList rightList, BiFunction itemCombiner); /** * Check if the list contains the specified item @@ -261,7 +261,8 @@ public interface IList { * its final state. */ ReducedType reduceAux(StateType initialValue, - BiFunction stateAccumulator, + BiFunction stateAccumulator, Function resultTransformer); /** diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java index 4fb7c2b..8522058 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java @@ -16,6 +16,11 @@ import java.util.function.Function; * */ public interface IMap { + /** + * Delete all the values in the map + */ + void clear(); + /** * Check if this map contains the specified key * @@ -68,6 +73,16 @@ public interface IMap { */ ValueType get(KeyType key); + default ValueType getOrDefault(KeyType key, ValueType defaultValue) { + try { + return get(key); + } catch (IllegalArgumentException iaex) { + // We don't care about this, because it indicates a key is + // missing + return defaultValue; + } + } + /** * Get the number of entries in this map * @@ -132,19 +147,4 @@ public interface IMap { * @return A list of values in this map */ IList valueList(); - - /** - * Delete all the values in the map - */ - void clear(); - - default ValueType getOrDefault(KeyType key, ValueType defaultValue) { - try { - return get(key); - } catch (IllegalArgumentException iaex) { - // We don't care about this, because it indicates a key is - // missing - return defaultValue; - } - } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java index e0c63e3..c773f4e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java @@ -43,7 +43,8 @@ public interface ITree { */ public ReturnedType collapse( Function leafTransform, - Function, NewType>> nodeCollapser, + Function, NewType>> nodeCollapser, Function resultTransformer); /** @@ -128,7 +129,8 @@ public interface ITree { * @return The tree with the transform applied to picked subtrees */ public ITree topDownTransform( - Function transformPicker, + Function transformPicker, UnaryOperator> transformer); /** diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java index cc60dab..d43e8d5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java @@ -27,6 +27,11 @@ final class TransformedValueMap transformer = transform; } + @Override + public void clear() { + mapToTransform.clear(); + } + @Override public boolean containsKey(OldKey key) { return mapToTransform.containsKey(key); @@ -97,9 +102,4 @@ final class TransformedValueMap public IList valueList() { return mapToTransform.valueList().map(transformer); } - - @Override - public void clear() { - mapToTransform.clear(); - } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java index 77b5673..68a0ae1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java @@ -95,7 +95,8 @@ public class Tree implements ITree { @Override public ReturnedType collapse( Function leafTransform, - Function, NewType>> nodeCollapser, + Function, NewType>> nodeCollapser, Function resultTransformer) { return resultTransformer @@ -129,16 +130,17 @@ public class Tree implements ITree { protected NewType internalCollapse( Function leafTransform, - Function, NewType>> nodeCollapser) { + Function, NewType>> nodeCollapser) { if (hasChildren) { - Function, NewType> nodeTransformer = nodeCollapser - .apply(data); + Function, + NewType> nodeTransformer = nodeCollapser.apply(data); - @SuppressWarnings("unchecked") - IList collapsedChildren = (IList) children.map((child) -> { - return child.collapse(leafTransform, nodeCollapser, - (subTreeVal) -> subTreeVal); - }); + IList collapsedChildren = (IList) children + .map((child) -> { + return child.collapse(leafTransform, nodeCollapser, + (subTreeVal) -> subTreeVal); + }); return nodeTransformer.apply(collapsedChildren); } @@ -195,7 +197,8 @@ public class Tree implements ITree { @Override public ITree topDownTransform( - Function transformPicker, + Function transformPicker, UnaryOperator> transformer) { TopDownTransformResult transformResult = transformPicker .apply(data); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java index a6d08a2..9817f91 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java @@ -81,7 +81,8 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { rightBranch.add(element, comparator); } default: - throw new IllegalStateException("Error: Comparator yielded invalid value"); + throw new IllegalStateException( + "Error: Comparator yielded invalid value"); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java index d3ebdac..a8f27c6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java @@ -31,21 +31,31 @@ public interface Bifunctor { * The function that maps over the right of the pair * @return A function that maps over both parts of the pair */ - public default Function, Bifunctor> bimap( - Function leftFunc, - Function rightFunc) { - Function, Bifunctor> bimappedFunc = ( - argPair) -> { - Function, Bifunctor> leftMapper = argPair - . fmapLeft(leftFunc); + public default Function, + Bifunctor> bimap( + Function leftFunc, + Function rightFunc) { + Function, + Bifunctor> bimappedFunc = (argPair) -> { + Function, + Bifunctor> leftMapper = argPair.< + OldLeft, OldRight, + NewLeft> fmapLeft(leftFunc); - Bifunctor leftMappedFunctor = leftMapper - .apply(argPair); - Function, Bifunctor> rightMapper = leftMappedFunctor - . fmapRight(rightFunc); + Bifunctor leftMappedFunctor = leftMapper + .apply(argPair); + Function, + Bifunctor> rightMapper = leftMappedFunctor + . fmapRight( + rightFunc); - return rightMapper.apply(leftMappedFunctor); - }; + return rightMapper.apply(leftMappedFunctor); + }; return bimappedFunc; } @@ -64,8 +74,10 @@ public interface Bifunctor { * pair * @return The function lifted to work over the left side of bifunctors */ - public Function, Bifunctor> fmapLeft( - Function func); + public Function, + Bifunctor> fmapLeft( + Function func); /** * Lift a function to operate over the right part of this pair @@ -82,8 +94,10 @@ public interface Bifunctor { * @return The function lifted to work over the right side of * bifunctors */ - public Function, Bifunctor> fmapRight( - Function func); + public Function, + Bifunctor> fmapRight( + Function func); /** * Get the value contained on the left of this bifunctor diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java index 76f48e2..10cfffe 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java @@ -27,8 +27,10 @@ public interface Functor { * @return The passed in function converted to work over a particular * type of functors */ - public Function, Functor> fmap( - Function func); + public Function, + Functor> fmap( + Function func); /** * Retrieve the thing inside this functor diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java index f7210b5..0a1efd5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java @@ -31,9 +31,14 @@ public class CollectorUtils { * The second collector to use * @return A collector that functions as mentioned above */ - public static Collector>, IPair> compoundCollect( - Collector firstCollector, - Collector secondCollector) { + public static Collector>, + IPair> compoundCollect( + Collector firstCollector, + Collector secondCollector) { return new CompoundCollector<>(firstCollector, secondCollector); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java index 60eb163..257f005 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java @@ -12,13 +12,16 @@ import bjc.utils.data.IPair; import bjc.utils.data.Identity; import bjc.utils.data.Pair; -final class CompoundCollector - implements - Collector>, IPair> { - private Set characteristicSet; +final class CompoundCollector implements + Collector>, + IPair> { + private Set< + java.util.stream.Collector.Characteristics> characteristicSet; private Collector firstCollector; - private Collector secondCollector; + private Collector secondCollector; public CompoundCollector( Collector firstCollector, @@ -31,11 +34,13 @@ final class CompoundCollector>, InitialType> accumulator() { + public BiConsumer>, + InitialType> accumulator() { BiConsumer firstAccumulator = firstCollector .accumulator(); - BiConsumer secondAccumulator = secondCollector - .accumulator(); + BiConsumer secondAccumulator = secondCollector + .accumulator(); return (state, value) -> { state.doWith((statePair) -> { @@ -48,15 +53,16 @@ final class CompoundCollector characteristics() { + public Set< + java.util.stream.Collector.Characteristics> characteristics() { return characteristicSet; } @Override public BinaryOperator>> combiner() { BinaryOperator firstCombiner = firstCollector.combiner(); - BinaryOperator secondCombiner = secondCollector - .combiner(); + BinaryOperator< + AuxType2> secondCombiner = secondCollector.combiner(); return (leftState, rightState) -> { return leftState.unwrap((leftPair) -> { @@ -69,7 +75,8 @@ final class CompoundCollector>, IPair> finisher() { + public Function>, + IPair> finisher() { return (state) -> { return state.unwrap((pair) -> { return pair.bind((leftVal, rightVal) -> { diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java index d65603b..3b03406 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -216,8 +216,10 @@ public class ListUtils { /* * Run up to a certain number of passes */ - for (int numberOfIterations = 0; numberOfIterations < MAX_NTRIESPART - && !rejectedElements.isEmpty(); numberOfIterations++) { + for (int numberOfIterations = 0; + numberOfIterations < MAX_NTRIESPART + && !rejectedElements.isEmpty(); + numberOfIterations++) { input.forEach(new GroupPartIteration<>(returnedList, currentPartition, rejectedElements, numberInCurrentPartition, numberPerPartition, @@ -261,42 +263,6 @@ public class ListUtils { return returnedList; } - /** - * Split tokens in a list of tokens into multiple tokens. - * - * The intended use is for expression parsers so that you can enter - * something like 1+1 instead of 1 + 1. - * - * @param input - * The tokens to split - * @param operators - * Pairs of operators to split on and regexes that match - * those operators - * @return A list of tokens split on all the operators - * - */ - public static IList splitTokens(IList input, - Deque> operators) { - if (input == null) { - throw new NullPointerException("Input must not be null"); - } else if (operators == null) { - throw new NullPointerException( - "Set of operators must not be null"); - } - - IHolder> returnedList = new Identity<>(input); - - operators.forEach((operator) -> { - returnedList.transform((oldReturn) -> { - return oldReturn.flatMap((token) -> { - return operator.merge(new TokenSplitter(token)); - }); - }); - }); - - return returnedList.getValue(); - } - public static IList padList(IList list, Function counter, int size, Supplier padSource) { @@ -337,4 +303,40 @@ public class ListUtils { return ret; } + + /** + * Split tokens in a list of tokens into multiple tokens. + * + * The intended use is for expression parsers so that you can enter + * something like 1+1 instead of 1 + 1. + * + * @param input + * The tokens to split + * @param operators + * Pairs of operators to split on and regexes that match + * those operators + * @return A list of tokens split on all the operators + * + */ + public static IList splitTokens(IList input, + Deque> operators) { + if (input == null) { + throw new NullPointerException("Input must not be null"); + } else if (operators == null) { + throw new NullPointerException( + "Set of operators must not be null"); + } + + IHolder> returnedList = new Identity<>(input); + + operators.forEach((operator) -> { + returnedList.transform((oldReturn) -> { + return oldReturn.flatMap((token) -> { + return operator.merge(new TokenSplitter(token)); + }); + }); + }); + + return returnedList.getValue(); + } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java index 1f8f61d..419c787 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java @@ -26,8 +26,8 @@ public class NumberUtils { } else { int result = 1; - for (int currentSub = 0; currentSub < power - + 1; currentSub++) { + for (int currentSub = 0; currentSub < power + 1; + currentSub++) { result *= value - currentSub; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index 6ddf420..7573bfb 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -85,8 +85,8 @@ public class StringUtils { * @return A string version of the deque, with allowance for an empty * deque */ - public static String printDeque( - Deque queue) { + public static < + ContainedType> String printDeque(Deque queue) { return queue.isEmpty() ? "(none)" : queue.toString(); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java index fe10741..062802c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java @@ -387,7 +387,8 @@ public class WeightedGrammar { WeightedRandom> rule = rules.get(ruleName); - IList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { IList> newRule = new FunctionalList<>(); @@ -447,7 +448,8 @@ public class WeightedGrammar { WeightedRandom> rule = rules.get(ruleName); - IList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { IList newCase = pair.merge((left, right) -> { @@ -501,7 +503,8 @@ public class WeightedGrammar { WeightedRandom> rule = rules.get(ruleName); - IList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((par) -> { IList newCase = par.merge((left, right) -> { diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java index 8246822..d38cadf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java @@ -169,8 +169,8 @@ public class SimpleInternalDialogs { throw new NullPointerException("Question must not be null"); } - int dialogResult = JOptionPane.showInternalConfirmDialog(parent, question, - title, JOptionPane.YES_NO_OPTION); + int dialogResult = JOptionPane.showInternalConfirmDialog(parent, + question, title, JOptionPane.YES_NO_OPTION); return (dialogResult == JOptionPane.YES_OPTION ? true : false); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java index a6eb57c..e512d6b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java @@ -11,17 +11,17 @@ import javax.swing.JTextArea; */ public class TextAreaOutputStream extends OutputStream { - private JTextArea textArea; + private JTextArea textArea; - public TextAreaOutputStream(JTextArea console) { - this.textArea = console; - } + public TextAreaOutputStream(JTextArea console) { + this.textArea = console; + } - @Override + @Override public void write(int b) throws IOException { - textArea.append("" + (char) b); - if (b == '\n') { - textArea.repaint(); - } - } + textArea.append("" + (char) b); + if (b == '\n') { + textArea.repaint(); + } + } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java index 8769902..553d201 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java @@ -91,8 +91,8 @@ public class ListParameterPanel extends JPanel { if (addAction != null) { addParam = new JButton("Add..."); addParam.addActionListener((event) -> { - DefaultListModel model = (DefaultListModel) list - .getModel(); + DefaultListModel< + E> model = (DefaultListModel) list.getModel(); model.addElement(addAction.get()); }); @@ -112,8 +112,8 @@ public class ListParameterPanel extends JPanel { if (removeAction != null) { removeParam = new JButton("Remove..."); removeParam.addActionListener((event) -> { - DefaultListModel model = (DefaultListModel) list - .getModel(); + DefaultListModel< + E> model = (DefaultListModel) list.getModel(); removeAction.accept(model.remove(list.getSelectedIndex())); }); diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java index 8884163..62aac0d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java @@ -18,6 +18,21 @@ import bjc.utils.gui.layout.HLayout; public class SimpleListPanel extends JPanel { private static final long serialVersionUID = 2719963952350133541L; + private static void addItem(DefaultListModel listModel, + Predicate itemVerifier, + Consumer onVerificationFailure, + JTextField addItemField) { + String potentialItem = addItemField.getText(); + + if (itemVerifier == null || itemVerifier.test(potentialItem)) { + listModel.addElement(potentialItem); + } else { + onVerificationFailure.accept(potentialItem); + } + + addItemField.setText(""); + } + public SimpleListPanel(String itemType, DefaultListModel listModel, Predicate itemVerifier, @@ -63,19 +78,4 @@ public class SimpleListPanel extends JPanel { add(itemInputPanel); } - - private static void addItem(DefaultListModel listModel, - Predicate itemVerifier, - Consumer onVerificationFailure, - JTextField addItemField) { - String potentialItem = addItemField.getText(); - - if (itemVerifier == null || itemVerifier.test(potentialItem)) { - listModel.addElement(potentialItem); - } else { - onVerificationFailure.accept(potentialItem); - } - - addItemField.setText(""); - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java index 1ad2ff5..1ee19f5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java @@ -26,11 +26,15 @@ import bjc.utils.funcdata.IMap; * */ public class RuleBasedConfigReader { - private BiConsumer> startRule; - private BiConsumer continueRule; - private Consumer endRule; + private BiConsumer> startRule; + private BiConsumer continueRule; + private Consumer< + E> endRule; - private IMap> pragmas; + private IMap> pragmas; /** * Create a new rule-based config reader @@ -43,7 +47,8 @@ public class RuleBasedConfigReader { * The action to fire when ending a rule */ public RuleBasedConfigReader( - BiConsumer> startRule, + BiConsumer> startRule, BiConsumer continueRule, Consumer endRule) { this.startRule = startRule; @@ -176,8 +181,8 @@ public class RuleBasedConfigReader { * @param startRule * The action to execute on starting of a rule */ - public void setStartRule( - BiConsumer> startRule) { + public void setStartRule(BiConsumer> startRule) { if (startRule == null) { throw new NullPointerException( "Action on rule start must be non-null"); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java index 2c77c5d..392a6c8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java @@ -25,8 +25,9 @@ public class RuleBasedReaderPragmas { * The function to invoke with the parsed integer * @return A pragma that functions as described above. */ - public static BiConsumer buildInteger( - String name, BiConsumer consumer) { + public static BiConsumer buildInteger(String name, + BiConsumer consumer) { return (tokenizer, state) -> { if (!tokenizer.hasMoreTokens()) { throw new PragmaFormatException("Pragma " + name @@ -62,8 +63,9 @@ public class RuleBasedReaderPragmas { * The function to invoke with the parsed string * @return A pragma that functions as described above. */ - public static BiConsumer buildStringCollapser( - String name, BiConsumer consumer) { + public static BiConsumer buildStringCollapser(String name, + BiConsumer consumer) { return (tokenizer, state) -> { if (!tokenizer.hasMoreTokens()) { throw new PragmaFormatException("Pragma " + name diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java index 1c1a6fb..7cfb9cd 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java @@ -13,8 +13,8 @@ import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; final class TokenTransformer implements Consumer { - private final class OperatorHandler implements - UnaryOperator>, ITree>> { + private final class OperatorHandler implements UnaryOperator< + IPair>, ITree>> { private TokenType element; public OperatorHandler(TokenType element) { @@ -29,8 +29,9 @@ final class TokenTransformer implements Consumer { }); } - private IPair>, ITree> handleOperator( - Deque> queuedASTs) { + private IPair>, + ITree> handleOperator( + Deque> queuedASTs) { ITree newAST; if (isSpecialOperator.test(element)) { @@ -57,18 +58,24 @@ final class TokenTransformer implements Consumer { } } - private IHolder>, ITree>> initialState; + private IHolder>, + ITree>> initialState; - private Predicate operatorPredicate; + private Predicate< + TokenType> operatorPredicate; - private Predicate isSpecialOperator; - private Function>, ITree>> handleSpecialOperator; + private Predicate< + TokenType> isSpecialOperator; + private Function>, + ITree>> handleSpecialOperator; public TokenTransformer( - IHolder>, ITree>> initialState, + IHolder>, + ITree>> initialState, Predicate operatorPredicate, Predicate isSpecialOperator, - Function>, ITree>> handleSpecialOperator) { + Function>, + ITree>> handleSpecialOperator) { this.initialState = initialState; this.operatorPredicate = operatorPredicate; this.isSpecialOperator = isSpecialOperator; diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java index 67a74d9..5184fa6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java @@ -68,7 +68,8 @@ public class TreeConstructor { IList tokens, Predicate operatorPredicate, Predicate isSpecialOperator, - Function>, ITree>> handleSpecialOperator) { + Function>, + ITree>> handleSpecialOperator) { if (tokens == null) { throw new NullPointerException("Tokens must not be null"); } else if (operatorPredicate == null) { @@ -79,8 +80,9 @@ public class TreeConstructor { "Special operator determiner must not be null"); } - IHolder>, ITree>> initialState = new Identity<>( - new Pair<>(new LinkedList<>(), null)); + IHolder>, + ITree>> initialState = new Identity<>( + new Pair<>(new LinkedList<>(), null)); tokens.forEach( new TokenTransformer<>(initialState, operatorPredicate, -- cgit v1.2.3