diff options
39 files changed, 385 insertions, 266 deletions
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 @@ <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath> 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"> <modelVersion>4.0.0</modelVersion> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> + <groupId>bjc</groupId> <artifactId>BJC-Utils2</artifactId> <version>0.1.0-SNAPSHOT</version> @@ -12,7 +24,6 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <jvmtarget>1.8</jvmtarget> </properties> <dependencies> 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<String, Function<Deque<ITree<String>>, ITree<String>>> operators = new FunctionalMap<>(); + IMap<String, Function<Deque<ITree<String>>, + ITree<String>>> 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 <ComponentType> * The type of component being read in */ -public class FileComponentRepository<ComponentType extends IDescribedComponent> +public class FileComponentRepository< + ComponentType extends IDescribedComponent> implements IComponentRepository<ComponentType> { // The logger to use for storing data about this class private static final Logger CLASS_LOGGER = Logger @@ -71,24 +72,25 @@ public class FileComponentRepository<ComponentType extends IDescribedComponent> // Predicate to use to traverse all the files in a directory, but // not recurse into sub-directories - BiPredicate<Path, BasicFileAttributes> 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<Path, + BasicFileAttributes> 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 <ComponentType> * The type of components contained in this repository */ -public interface IComponentRepository<ComponentType extends IDescribedComponent> { +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<OldType, BoundContainedType> /* * Transformations currently pending on the bound value */ - private IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>(); + private IList<UnaryOperator< + BoundContainedType>> actions = new FunctionalList<>(); /* * Create a new bound lazy value @@ -52,7 +53,8 @@ class BoundLazy<OldType, BoundContainedType> /* * Prepare a list of pending actions */ - IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + BoundContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); /* @@ -91,7 +93,8 @@ class BoundLazy<OldType, BoundContainedType> public <MappedType> IHolder<MappedType> map( Function<BoundContainedType, MappedType> mapper) { // Prepare a list of pending actions - IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + BoundContainedType>> 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<OldLeft, OldRight, NewLeft, NewRight> implements IPair<NewLeft, NewRight> { - private Supplier<OldLeft> leftSupplier; - private Supplier<OldRight> rightSupplier; + private Supplier< + OldLeft> leftSupplier; + private Supplier< + OldRight> rightSupplier; private BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder; - private IPair<NewLeft, NewRight> boundPair; + private IPair<NewLeft, + NewRight> boundPair; private boolean pairBound; public BoundLazyPair(Supplier<OldLeft> leftSupp, - Supplier<OldRight> rightSupp, - BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) { + Supplier<OldRight> rightSupp, BiFunction<OldLeft, OldRight, + IPair<NewLeft, NewRight>> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; binder = bindr; @@ -25,9 +28,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) { - IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>( - boundPair); + BiFunction<NewLeft, NewRight, + IPair<BoundLeft, BoundRight>> bindr) { + IHolder<IPair<NewLeft, + NewRight>> newPair = new Identity<>(boundPair); IHolder<Boolean> newPairMade = new Identity<>(pairBound); Supplier<NewLeft> leftSupp = () -> { @@ -90,10 +94,13 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<NewLeft, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<NewRight, OtherRight, + CombinedRight> 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<LeftType, RightType> * The value to put on the left * @return An either with the left side occupied */ - public static <LeftType, RightType> Either<LeftType, RightType> fromLeft( - LeftType left) { + public static <LeftType, + RightType> Either<LeftType, RightType> fromLeft( + LeftType left) { return new Either<>(left, null); } + /** * Create a new either with the right value occupied * @@ -41,8 +43,9 @@ public class Either<LeftType, RightType> * The value to put on the right * @return An either with the right side occupied */ - public static <LeftType, RightType> Either<LeftType, RightType> fromRight( - RightType right) { + public static <LeftType, + RightType> Either<LeftType, RightType> fromRight( + RightType right) { return new Either<>(null, right); } @@ -64,7 +67,8 @@ public class Either<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { return binder.apply(leftVal, rightVal); } @@ -89,10 +93,13 @@ public class Either<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> 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<OldType, NewLeft, NewRight> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) { - IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>( - boundPair); + BiFunction<NewLeft, NewRight, + IPair<BoundLeft, BoundRight>> bindr) { + IHolder<IPair<NewLeft, + NewRight>> newPair = new Identity<>(boundPair); IHolder<Boolean> newPairMade = new Identity<>(pairBound); Supplier<NewLeft> leftSupp = () -> { @@ -80,10 +81,13 @@ class HalfBoundLazyPair<OldType, NewLeft, NewRight> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<NewLeft, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<NewRight, OtherRight, + CombinedRight> 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<ContainedType> extends Functor<ContainedType> { } @Override - default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( - Function<ArgType, ReturnType> func) { + default <ArgType, + ReturnType> Function<Functor<ArgType>, + Functor<ReturnType>> fmap( + Function<ArgType, ReturnType> 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<LeftType, RightType> * @return The bound pair */ public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder); + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder); /** * Bind a function to the left value in this pair @@ -67,8 +68,10 @@ public interface IPair<LeftType, RightType> * The pair to combine with * @return The pairs, pairwise combined together */ - public default <OtherLeft, OtherRight> IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>> combine( - IPair<OtherLeft, OtherRight> otherPair) { + public default <OtherLeft, + OtherRight> IPair<IPair<LeftType, OtherLeft>, + IPair<RightType, OtherRight>> combine( + IPair<OtherLeft, OtherRight> otherPair) { return combine(otherPair, (left, otherLeft) -> new Pair<>(left, otherLeft), (right, otherRight) -> new Pair<>(right, otherRight)); @@ -91,10 +94,13 @@ public interface IPair<LeftType, RightType> * @param rightCombiner * @return A pair with its values combined */ - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner); + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> rightCombiner); /** * Immediately perfom the specified action with the contents of this @@ -112,22 +118,26 @@ public interface IPair<LeftType, RightType> } @Override - default <OldLeft, OldRight, NewLeft> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> fmapLeft( - Function<OldLeft, NewLeft> func) { + default <OldLeft, OldRight, + NewLeft> Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, OldRight>> fmapLeft( + Function<OldLeft, NewLeft> func) { return (argumentPair) -> { if (!(argumentPair instanceof IPair<?, ?>)) { throw new IllegalArgumentException( "This function can only be applied to instances of IPair"); } - IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, + OldRight>) argumentPair; return argPair.mapLeft(func); }; } @Override - default <OldLeft, OldRight, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> + default <OldLeft, OldRight, NewRight> Function< + Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> fmapRight(Function<OldRight, NewRight> func) { return (argumentPair) -> { @@ -136,7 +146,8 @@ public interface IPair<LeftType, RightType> "This function can only be applied to instances of IPair"); } - IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, OldRight>) argumentPair; + IPair<OldLeft, OldRight> argPair = (IPair<OldLeft, + OldRight>) 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<ContainedType> implements IHolder<ContainedType> { private Supplier<ContainedType> valueSupplier; - private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>(); + private IList<UnaryOperator< + ContainedType>> actions = new FunctionalList<>(); private boolean valueMaterialized; @@ -58,7 +59,8 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> { @Override public <BoundType> IHolder<BoundType> bind( Function<ContainedType, IHolder<BoundType>> binder) { - IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + ContainedType>> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); @@ -86,7 +88,8 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> { @Override public <MappedType> IHolder<MappedType> map( Function<ContainedType, MappedType> mapper) { - IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>(); + IList<UnaryOperator< + ContainedType>> 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<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { return new BoundLazyPair<>(leftSupplier, rightSupplier, binder); } @@ -96,10 +97,13 @@ public class LazyPair<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> 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<LeftType, RightType> @Override public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind( - BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) { + BiFunction<LeftType, RightType, + IPair<BoundLeft, BoundRight>> binder) { if (binder == null) { throw new NullPointerException("Binder must not be null."); } @@ -70,10 +71,13 @@ public class Pair<LeftType, RightType> } @Override - public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine( - IPair<OtherLeft, OtherRight> otherPair, - BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, - BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { + public <OtherLeft, OtherRight, CombinedLeft, + CombinedRight> IPair<CombinedLeft, CombinedRight> combine( + IPair<OtherLeft, OtherRight> otherPair, + BiFunction<LeftType, OtherLeft, + CombinedLeft> leftCombiner, + BiFunction<RightType, OtherRight, + CombinedRight> 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 @@ -18,6 +18,11 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { } @Override + public void clear() { + store.clear(); + } + + @Override public boolean containsKey(KeyType key) { if (store.containsKey(key)) { return true; @@ -92,9 +97,4 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { 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<E> implements Cloneable, IList<E> { // Get the iterator for the other list Iterator<T> rightIterator = rightList.toIterable().iterator(); - for (Iterator<E> leftIterator = wrappedList - .iterator(); leftIterator.hasNext() - && rightIterator.hasNext();) { + for (Iterator<E> 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<KeyType, ValueType> wrappedMap = wrap; } + @Override + public void clear() { + wrappedMap.clear(); + } + /* * (non-Javadoc) * @@ -175,9 +180,4 @@ public class FunctionalMap<KeyType, ValueType> 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<ContainedType> { */ public default <StateType, ReducedType> ReducedType collect( Collector<ContainedType, StateType, ReducedType> collector) { - BiConsumer<StateType, ContainedType> accumulator = collector - .accumulator(); + BiConsumer<StateType, + ContainedType> accumulator = collector.accumulator(); return reduceAux(collector.supplier().get(), (value, state) -> { accumulator.accept(state, value); @@ -92,8 +92,8 @@ public interface IList<ContainedType> { * @return A new list containing the merged pairs of lists. */ <OtherType, CombinedType> IList<CombinedType> combineWith( - IList<OtherType> rightList, - BiFunction<ContainedType, OtherType, CombinedType> itemCombiner); + IList<OtherType> rightList, BiFunction<ContainedType, + OtherType, CombinedType> itemCombiner); /** * Check if the list contains the specified item @@ -261,7 +261,8 @@ public interface IList<ContainedType> { * its final state. */ <StateType, ReducedType> ReducedType reduceAux(StateType initialValue, - BiFunction<ContainedType, StateType, StateType> stateAccumulator, + BiFunction<ContainedType, StateType, + StateType> stateAccumulator, Function<StateType, ReducedType> 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 @@ -17,6 +17,11 @@ import java.util.function.Function; */ public interface IMap<KeyType, ValueType> { /** + * Delete all the values in the map + */ + void clear(); + + /** * Check if this map contains the specified key * * @param key @@ -68,6 +73,16 @@ public interface IMap<KeyType, ValueType> { */ 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<KeyType, ValueType> { * @return A list of values in this map */ IList<ValueType> 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<ContainedType> { */ public <NewType, ReturnedType> ReturnedType collapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser, + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser, Function<NewType, ReturnedType> resultTransformer); /** @@ -128,7 +129,8 @@ public interface ITree<ContainedType> { * @return The tree with the transform applied to picked subtrees */ public ITree<ContainedType> topDownTransform( - Function<ContainedType, TopDownTransformResult> transformPicker, + Function<ContainedType, + TopDownTransformResult> transformPicker, UnaryOperator<ITree<ContainedType>> 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 @@ -28,6 +28,11 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> } @Override + public void clear() { + mapToTransform.clear(); + } + + @Override public boolean containsKey(OldKey key) { return mapToTransform.containsKey(key); } @@ -97,9 +102,4 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> public IList<NewValue> 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<ContainedType> implements ITree<ContainedType> { @Override public <NewType, ReturnedType> ReturnedType collapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser, + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser, Function<NewType, ReturnedType> resultTransformer) { return resultTransformer @@ -129,16 +130,17 @@ public class Tree<ContainedType> implements ITree<ContainedType> { protected <NewType> NewType internalCollapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser) { + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser) { if (hasChildren) { - Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser - .apply(data); + Function<IList<NewType>, + NewType> nodeTransformer = nodeCollapser.apply(data); - @SuppressWarnings("unchecked") - IList<NewType> collapsedChildren = (IList<NewType>) children.map((child) -> { - return child.collapse(leafTransform, nodeCollapser, - (subTreeVal) -> subTreeVal); - }); + IList<NewType> collapsedChildren = (IList<NewType>) children + .map((child) -> { + return child.collapse(leafTransform, nodeCollapser, + (subTreeVal) -> subTreeVal); + }); return nodeTransformer.apply(collapsedChildren); } @@ -195,7 +197,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public ITree<ContainedType> topDownTransform( - Function<ContainedType, TopDownTransformResult> transformPicker, + Function<ContainedType, + TopDownTransformResult> transformPicker, UnaryOperator<ITree<ContainedType>> 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<T> extends BinarySearchTreeLeaf<T> { 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<LeftType, RightType> { * The function that maps over the right of the pair * @return A function that maps over both parts of the pair */ - public default <OldLeft, OldRight, NewLeft, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, NewRight>> bimap( - Function<OldLeft, NewLeft> leftFunc, - Function<OldRight, NewRight> rightFunc) { - Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, NewRight>> bimappedFunc = ( - argPair) -> { - Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> leftMapper = argPair - .<OldLeft, OldRight, NewLeft> fmapLeft(leftFunc); + public default <OldLeft, OldRight, NewLeft, + NewRight> Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, NewRight>> bimap( + Function<OldLeft, NewLeft> leftFunc, + Function<OldRight, NewRight> rightFunc) { + Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, NewRight>> bimappedFunc = (argPair) -> { + Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, + OldRight>> leftMapper = argPair.< + OldLeft, OldRight, + NewLeft> fmapLeft(leftFunc); - Bifunctor<NewLeft, OldRight> leftMappedFunctor = leftMapper - .apply(argPair); - Function<Bifunctor<NewLeft, OldRight>, Bifunctor<NewLeft, NewRight>> rightMapper = leftMappedFunctor - .<NewLeft, OldRight, NewRight> fmapRight(rightFunc); + Bifunctor<NewLeft, + OldRight> leftMappedFunctor = leftMapper + .apply(argPair); + Function<Bifunctor<NewLeft, OldRight>, + Bifunctor<NewLeft, + NewRight>> rightMapper = leftMappedFunctor + .<NewLeft, OldRight, + NewRight> fmapRight( + rightFunc); - return rightMapper.apply(leftMappedFunctor); - }; + return rightMapper.apply(leftMappedFunctor); + }; return bimappedFunc; } @@ -64,8 +74,10 @@ public interface Bifunctor<LeftType, RightType> { * pair * @return The function lifted to work over the left side of bifunctors */ - public <OldLeft, OldRight, NewLeft> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> fmapLeft( - Function<OldLeft, NewLeft> func); + public <OldLeft, OldRight, + NewLeft> Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<NewLeft, OldRight>> fmapLeft( + Function<OldLeft, NewLeft> func); /** * Lift a function to operate over the right part of this pair @@ -82,8 +94,10 @@ public interface Bifunctor<LeftType, RightType> { * @return The function lifted to work over the right side of * bifunctors */ - public <OldLeft, OldRight, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> fmapRight( - Function<OldRight, NewRight> func); + public <OldLeft, OldRight, + NewRight> Function<Bifunctor<OldLeft, OldRight>, + Bifunctor<OldLeft, NewRight>> fmapRight( + Function<OldRight, NewRight> 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<ContainedType> { * @return The passed in function converted to work over a particular * type of functors */ - public <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( - Function<ArgType, ReturnType> func); + public <ArgType, + ReturnType> Function<Functor<ArgType>, + Functor<ReturnType>> fmap( + Function<ArgType, ReturnType> 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 <InitialType, AuxType1, AuxType2, FinalType1, FinalType2> Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> compoundCollect( - Collector<InitialType, AuxType1, FinalType1> firstCollector, - Collector<InitialType, AuxType2, FinalType2> secondCollector) { + public static <InitialType, AuxType1, AuxType2, FinalType1, + FinalType2> Collector<InitialType, + IHolder<IPair<AuxType1, AuxType2>>, + IPair<FinalType1, FinalType2>> compoundCollect( + Collector<InitialType, AuxType1, + FinalType1> firstCollector, + Collector<InitialType, AuxType2, + FinalType2> 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<InitialType, AuxType1, AuxType2, FinalType1, FinalType2> - implements - Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> { - private Set<java.util.stream.Collector.Characteristics> characteristicSet; +final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, + FinalType2> implements + Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, + IPair<FinalType1, FinalType2>> { + private Set< + java.util.stream.Collector.Characteristics> characteristicSet; private Collector<InitialType, AuxType1, FinalType1> firstCollector; - private Collector<InitialType, AuxType2, FinalType2> secondCollector; + private Collector<InitialType, AuxType2, + FinalType2> secondCollector; public CompoundCollector( Collector<InitialType, AuxType1, FinalType1> firstCollector, @@ -31,11 +34,13 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, InitialType> accumulator() { + public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, + InitialType> accumulator() { BiConsumer<AuxType1, InitialType> firstAccumulator = firstCollector .accumulator(); - BiConsumer<AuxType2, InitialType> secondAccumulator = secondCollector - .accumulator(); + BiConsumer<AuxType2, + InitialType> secondAccumulator = secondCollector + .accumulator(); return (state, value) -> { state.doWith((statePair) -> { @@ -48,15 +53,16 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Set<java.util.stream.Collector.Characteristics> characteristics() { + public Set< + java.util.stream.Collector.Characteristics> characteristics() { return characteristicSet; } @Override public BinaryOperator<IHolder<IPair<AuxType1, AuxType2>>> combiner() { BinaryOperator<AuxType1> firstCombiner = firstCollector.combiner(); - BinaryOperator<AuxType2> secondCombiner = secondCollector - .combiner(); + BinaryOperator< + AuxType2> secondCombiner = secondCollector.combiner(); return (leftState, rightState) -> { return leftState.unwrap((leftPair) -> { @@ -69,7 +75,8 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Function<IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> finisher() { + public Function<IHolder<IPair<AuxType1, AuxType2>>, + IPair<FinalType1, FinalType2>> 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<String> splitTokens(IList<String> input, - Deque<IPair<String, String>> 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<IList<String>> 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 <E> IList<E> padList(IList<E> list, Function<E, Integer> counter, int size, Supplier<E> 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<String> splitTokens(IList<String> input, + Deque<IPair<String, String>> 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<IList<String>> 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 <ContainedType> String printDeque( - Deque<ContainedType> queue) { + public static < + ContainedType> String printDeque(Deque<ContainedType> 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<E> { WeightedRandom<IList<E>> rule = rules.get(ruleName); - IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>(); + IList<IPair<Integer, + IList<E>>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { IList<IList<E>> newRule = new FunctionalList<>(); @@ -447,7 +448,8 @@ public class WeightedGrammar<E> { WeightedRandom<IList<E>> rule = rules.get(ruleName); - IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>(); + IList<IPair<Integer, + IList<E>>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { IList<E> newCase = pair.merge((left, right) -> { @@ -501,7 +503,8 @@ public class WeightedGrammar<E> { WeightedRandom<IList<E>> rule = rules.get(ruleName); - IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>(); + IList<IPair<Integer, + IList<E>>> newResults = new FunctionalList<>(); rule.getValues().forEach((par) -> { IList<E> 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<E> extends JPanel { if (addAction != null) { addParam = new JButton("Add..."); addParam.addActionListener((event) -> { - DefaultListModel<E> model = (DefaultListModel<E>) list - .getModel(); + DefaultListModel< + E> model = (DefaultListModel<E>) list.getModel(); model.addElement(addAction.get()); }); @@ -112,8 +112,8 @@ public class ListParameterPanel<E> extends JPanel { if (removeAction != null) { removeParam = new JButton("Remove..."); removeParam.addActionListener((event) -> { - DefaultListModel<E> model = (DefaultListModel<E>) list - .getModel(); + DefaultListModel< + E> model = (DefaultListModel<E>) 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<String> listModel, + Predicate<String> itemVerifier, + Consumer<String> 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<String> listModel, Predicate<String> itemVerifier, @@ -63,19 +78,4 @@ public class SimpleListPanel extends JPanel { add(itemInputPanel); } - - private static void addItem(DefaultListModel<String> listModel, - Predicate<String> itemVerifier, - Consumer<String> 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<E> { - private BiConsumer<FunctionalStringTokenizer, IPair<String, E>> startRule; - private BiConsumer<FunctionalStringTokenizer, E> continueRule; - private Consumer<E> endRule; + private BiConsumer<FunctionalStringTokenizer, IPair<String, + E>> startRule; + private BiConsumer<FunctionalStringTokenizer, + E> continueRule; + private Consumer< + E> endRule; - private IMap<String, BiConsumer<FunctionalStringTokenizer, E>> pragmas; + private IMap<String, BiConsumer<FunctionalStringTokenizer, + E>> pragmas; /** * Create a new rule-based config reader @@ -43,7 +47,8 @@ public class RuleBasedConfigReader<E> { * The action to fire when ending a rule */ public RuleBasedConfigReader( - BiConsumer<FunctionalStringTokenizer, IPair<String, E>> startRule, + BiConsumer<FunctionalStringTokenizer, + IPair<String, E>> startRule, BiConsumer<FunctionalStringTokenizer, E> continueRule, Consumer<E> endRule) { this.startRule = startRule; @@ -176,8 +181,8 @@ public class RuleBasedConfigReader<E> { * @param startRule * The action to execute on starting of a rule */ - public void setStartRule( - BiConsumer<FunctionalStringTokenizer, IPair<String, E>> startRule) { + public void setStartRule(BiConsumer<FunctionalStringTokenizer, + IPair<String, E>> 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 <StateType> BiConsumer<FunctionalStringTokenizer, StateType> buildInteger( - String name, BiConsumer<Integer, StateType> consumer) { + public static <StateType> BiConsumer<FunctionalStringTokenizer, + StateType> buildInteger(String name, + BiConsumer<Integer, StateType> 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 <StateType> BiConsumer<FunctionalStringTokenizer, StateType> buildStringCollapser( - String name, BiConsumer<String, StateType> consumer) { + public static <StateType> BiConsumer<FunctionalStringTokenizer, + StateType> buildStringCollapser(String name, + BiConsumer<String, StateType> 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<TokenType> implements Consumer<TokenType> { - private final class OperatorHandler implements - UnaryOperator<IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> { + private final class OperatorHandler implements UnaryOperator< + IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> { private TokenType element; public OperatorHandler(TokenType element) { @@ -29,8 +29,9 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> { }); } - private IPair<Deque<ITree<TokenType>>, ITree<TokenType>> handleOperator( - Deque<ITree<TokenType>> queuedASTs) { + private IPair<Deque<ITree<TokenType>>, + ITree<TokenType>> handleOperator( + Deque<ITree<TokenType>> queuedASTs) { ITree<TokenType> newAST; if (isSpecialOperator.test(element)) { @@ -57,18 +58,24 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> { } } - private IHolder<IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> initialState; + private IHolder<IPair<Deque<ITree<TokenType>>, + ITree<TokenType>>> initialState; - private Predicate<TokenType> operatorPredicate; + private Predicate< + TokenType> operatorPredicate; - private Predicate<TokenType> isSpecialOperator; - private Function<TokenType, Function<Deque<ITree<TokenType>>, ITree<TokenType>>> handleSpecialOperator; + private Predicate< + TokenType> isSpecialOperator; + private Function<TokenType, Function<Deque<ITree<TokenType>>, + ITree<TokenType>>> handleSpecialOperator; public TokenTransformer( - IHolder<IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> initialState, + IHolder<IPair<Deque<ITree<TokenType>>, + ITree<TokenType>>> initialState, Predicate<TokenType> operatorPredicate, Predicate<TokenType> isSpecialOperator, - Function<TokenType, Function<Deque<ITree<TokenType>>, ITree<TokenType>>> handleSpecialOperator) { + Function<TokenType, Function<Deque<ITree<TokenType>>, + ITree<TokenType>>> 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<TokenType> tokens, Predicate<TokenType> operatorPredicate, Predicate<TokenType> isSpecialOperator, - Function<TokenType, Function<Deque<ITree<TokenType>>, ITree<TokenType>>> handleSpecialOperator) { + Function<TokenType, Function<Deque<ITree<TokenType>>, + ITree<TokenType>>> 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<IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> initialState = new Identity<>( - new Pair<>(new LinkedList<>(), null)); + IHolder<IPair<Deque<ITree<TokenType>>, + ITree<TokenType>>> initialState = new Identity<>( + new Pair<>(new LinkedList<>(), null)); tokens.forEach( new TokenTransformer<>(initialState, operatorPredicate, |
