diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2018-03-01 14:53:15 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2018-03-01 14:53:15 -0500 |
| commit | 10beb8e502ec8cbb02162a09da2d826ea2a1b1fc (patch) | |
| tree | 6f04883aee2b8300c3989067d02f6245f1aee187 /base/src/main/java/bjc/utils | |
| parent | c6fa9c56ee7d339f4b7d49e528bde1b15039e359 (diff) | |
Format pass
Diffstat (limited to 'base/src/main/java/bjc/utils')
38 files changed, 530 insertions, 538 deletions
diff --git a/base/src/main/java/bjc/utils/PropertyDB.java b/base/src/main/java/bjc/utils/PropertyDB.java index 9f95d0a..77ebb3d 100644 --- a/base/src/main/java/bjc/utils/PropertyDB.java +++ b/base/src/main/java/bjc/utils/PropertyDB.java @@ -15,8 +15,8 @@ import bjc.utils.ioutils.SimpleProperties; * */ public class PropertyDB { - private static SimpleProperties regexes; - private static Map<String, Pattern> compiledRegexes; + private static SimpleProperties regexes; + private static Map<String, Pattern> compiledRegexes; private static SimpleProperties formats; diff --git a/base/src/main/java/bjc/utils/cli/CLICommander.java b/base/src/main/java/bjc/utils/cli/CLICommander.java index ca41c98..ad3bea9 100644 --- a/base/src/main/java/bjc/utils/cli/CLICommander.java +++ b/base/src/main/java/bjc/utils/cli/CLICommander.java @@ -13,9 +13,9 @@ import java.util.Scanner; */ public class CLICommander { /* The streams used for input and normal/error output. */ - private final InputStream input; - private final OutputStream output; - private final OutputStream error; + private final InputStream input; + private final OutputStream output; + private final OutputStream error; /* The command mode to start execution in. */ private CommandMode initialMode; diff --git a/base/src/main/java/bjc/utils/cli/GenericCommandMode.java b/base/src/main/java/bjc/utils/cli/GenericCommandMode.java index a642fe8..7be5454 100644 --- a/base/src/main/java/bjc/utils/cli/GenericCommandMode.java +++ b/base/src/main/java/bjc/utils/cli/GenericCommandMode.java @@ -29,8 +29,8 @@ public class GenericCommandMode implements CommandMode { private BiConsumer<String, String[]> unknownCommandHandler; /* The functions to use for input/output */ - private final Consumer<String> errorOutput; - private final Consumer<String> normalOutput; + private final Consumer<String> errorOutput; + private final Consumer<String> normalOutput; /* The name of this command mode, or null if it is unnamed */ private String modeName; diff --git a/base/src/main/java/bjc/utils/cli/GenericHelp.java b/base/src/main/java/bjc/utils/cli/GenericHelp.java index 9fca3a9..2e74a6c 100644 --- a/base/src/main/java/bjc/utils/cli/GenericHelp.java +++ b/base/src/main/java/bjc/utils/cli/GenericHelp.java @@ -7,8 +7,8 @@ package bjc.utils.cli; */ public class GenericHelp implements CommandHelp { /* The strings for this help topic. */ - private final String summary; - private final String description; + private final String summary; + private final String description; /** * Create a new help topic. diff --git a/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java b/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java index ac62c80..5b14a58 100644 --- a/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java +++ b/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java @@ -35,11 +35,11 @@ public class BlockReaderCLI { /** * All of the configured block readers. */ - public final Map<String, BlockReader> readers; + public final Map<String, BlockReader> readers; /** * All of the configured I/O sources. */ - public final Map<String, Reader> sources; + public final Map<String, Reader> sources; /** * Create a new set of state for the block reader. diff --git a/base/src/main/java/bjc/utils/cli/objects/Command.java b/base/src/main/java/bjc/utils/cli/objects/Command.java index 04cdfd9..c4b2a48 100644 --- a/base/src/main/java/bjc/utils/cli/objects/Command.java +++ b/base/src/main/java/bjc/utils/cli/objects/Command.java @@ -38,15 +38,15 @@ public class Command { /** * The full text of this command. */ - public final String fullCommand; + public final String fullCommand; /** * The text of this command without its name. */ - public final String remnCommand; + public final String remnCommand; /** * The name of this command. */ - public final String nameCommand; + public final String nameCommand; /** * The name of the I/O source this command was read from. diff --git a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java index aa9bcf3..45d27ce 100644 --- a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java +++ b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java @@ -26,8 +26,8 @@ public class DefineCLI { static class DefineState { public final Map<String, UnaryOperator<String>> defines; - public final Map<String, String> strings; - public final Map<String, String> formats; + public final Map<String, String> strings; + public final Map<String, String> formats; public final Map<String, Pattern> patterns; diff --git a/base/src/main/java/bjc/utils/components/ComponentDescription.java b/base/src/main/java/bjc/utils/components/ComponentDescription.java index 222dc09..57005e2 100644 --- a/base/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/base/src/main/java/bjc/utils/components/ComponentDescription.java @@ -18,13 +18,13 @@ public class ComponentDescription implements IDescribedComponent { } /** The author of the component */ - private final String author; + private final String author; /** The description of the component */ - private final String description; + private final String description; /** The name of the component */ - private final String name; + private final String name; /** The version of the component */ - private final int version; + private final int version; /** * Create a new component description. diff --git a/base/src/main/java/bjc/utils/data/CircularIterator.java b/base/src/main/java/bjc/utils/data/CircularIterator.java index 507ee01..4558b63 100644 --- a/base/src/main/java/bjc/utils/data/CircularIterator.java +++ b/base/src/main/java/bjc/utils/data/CircularIterator.java @@ -12,8 +12,8 @@ import java.util.Iterator; */ public class CircularIterator<E> implements Iterator<E> { /* The iterable, and our current iterator into it. */ - private Iterable<E> source; - private Iterator<E> curr; + private Iterable<E> source; + private Iterator<E> curr; /* Our current element. */ private E curElm; diff --git a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java b/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java index 1e69071..8914ad4 100644 --- a/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java +++ b/base/src/main/java/bjc/utils/data/TopDownTransformIterator.java @@ -25,22 +25,22 @@ import java.util.function.Function; * The type of the nodes in the tree. */ public class TopDownTransformIterator<ContainedType> implements Iterator<ITree<ContainedType>> { - private final Function<ContainedType, TopDownTransformResult> picker; - private final BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transform; + private final Function<ContainedType, TopDownTransformResult> picker; + private final BiFunction<ITree<ContainedType>, Consumer<Iterator<ITree<ContainedType>>>, ITree<ContainedType>> transform; - private ITree<ContainedType> preParent; - private ITree<ContainedType> postParent; + private ITree<ContainedType> preParent; + private ITree<ContainedType> postParent; - private final Deque<ITree<ContainedType>> preChildren; - private final Deque<ITree<ContainedType>> postChildren; + private final Deque<ITree<ContainedType>> preChildren; + private final Deque<ITree<ContainedType>> postChildren; private TopDownTransformIterator<ContainedType> curChild; - private boolean done; - private boolean initial; + private boolean done; + private boolean initial; - private final Deque<Iterator<ITree<ContainedType>>> toYield; - private Iterator<ITree<ContainedType>> curYield; + private final Deque<Iterator<ITree<ContainedType>>> toYield; + private Iterator<ITree<ContainedType>> curYield; /** * Create a new tree iterator. diff --git a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java b/base/src/main/java/bjc/utils/data/internals/WrappedOption.java index b2fe71f..19d5e26 100644 --- a/base/src/main/java/bjc/utils/data/internals/WrappedOption.java +++ b/base/src/main/java/bjc/utils/data/internals/WrappedOption.java @@ -10,7 +10,8 @@ import bjc.utils.data.Option; * A wrapped optional value. * * @author Ben Culkin. - * @param <ContainedType> The wrapped type. + * @param <ContainedType> + * The wrapped type. */ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { /* The held value. */ diff --git a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java index 1cf3d88..60a2765 100644 --- a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java @@ -16,10 +16,10 @@ import bjc.utils.gui.layout.HLayout; public class HolderOutputPanel extends JPanel { private static final long serialVersionUID = 166573313903782080L; - private Timer updater; - private final JLabel value; - private final int nDelay; - private final IHolder<String> val; + private Timer updater; + private final JLabel value; + private final int nDelay; + private final IHolder<String> val; /** * Create a new display panel, backed by a holder diff --git a/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java b/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java index ff4c161..da87357 100644 --- a/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java @@ -21,8 +21,8 @@ public class SliderInputPanel extends JPanel { private final class NumberFormatter extends JFormattedTextField.AbstractFormatter { private static final long serialVersionUID = -4448291795913908270L; - private final int minValue; - private final int maxValue; + private final int minValue; + private final int maxValue; private final int initValue; @@ -71,11 +71,11 @@ public class SliderInputPanel extends JPanel { /** * The minimum value of the slider */ - public final int minValue; + public final int minValue; /** * The maximum value of the slider */ - public final int maxValue; + public final int maxValue; /** * The initial value of the slider @@ -113,9 +113,9 @@ public class SliderInputPanel extends JPanel { } } - private static final long serialVersionUID = 2956394160569961404L; - private final JSlider slider; - private final JFormattedTextField field; + private static final long serialVersionUID = 2956394160569961404L; + private final JSlider slider; + private final JFormattedTextField field; /** * Create a new slider input panel diff --git a/base/src/main/java/bjc/utils/ioutils/Prompter.java b/base/src/main/java/bjc/utils/ioutils/Prompter.java index b318222..f39020d 100644 --- a/base/src/main/java/bjc/utils/ioutils/Prompter.java +++ b/base/src/main/java/bjc/utils/ioutils/Prompter.java @@ -12,8 +12,8 @@ import bjc.utils.ioutils.blocks.TriggeredBlockReader; * */ public final class Prompter implements Runnable { - private String promt; - private final PrintStream printer; + private String promt; + private final PrintStream printer; /** * Create a new prompter using the specified prompt. diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java index 36e0ac1..7d08c7e 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java @@ -29,9 +29,9 @@ public class BoundBlockReader implements BlockReader { public void close() throws IOException; } - private BooleanSupplier checker; - private Supplier<Block> getter; - private Closer closer; + private BooleanSupplier checker; + private Supplier<Block> getter; + private Closer closer; private Block current; diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java index 070713d..d4ca439 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java @@ -22,8 +22,8 @@ public class FilteredBlockReader implements BlockReader { * * Both have already been checked for the predicate. */ - private Block current; - private Block pending; + private Block current; + private Block pending; /* * Number of blocks that passed the predicate. diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java index bab463e..8636247 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java @@ -22,8 +22,8 @@ public class FlatMappedBlockReader implements BlockReader { /* * The current block, and any blocks pending from the last source block. */ - private Iterator<Block> pending; - private Block current; + private Iterator<Block> pending; + private Block current; /* * The operator to open blocks with. diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java index af138e7..48c4963 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java @@ -17,8 +17,8 @@ public class LayeredBlockReader implements BlockReader { /* * The readers to drain from. */ - private final BlockReader first; - private final BlockReader second; + private final BlockReader first; + private final BlockReader second; /* * The current block number. diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java index 4b7f76b..3814e41 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java @@ -31,8 +31,8 @@ public class SimpleBlockReader implements BlockReader { /* * Info about the current block. */ - private int blockNo; - private int lineNo; + private int blockNo; + private int lineNo; /** * Create a new block reader. diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java index 91952fc..73badcd 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java @@ -11,8 +11,8 @@ import bjc.utils.data.BooleanToggle; * */ public class ToggledBlockReader implements BlockReader { - private BlockReader leftSource; - private BlockReader rightSource; + private BlockReader leftSource; + private BlockReader rightSource; /* We choose the left source when this is true. */ private BooleanToggle leftToggle; diff --git a/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java b/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java index a535697..0625ff8 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java +++ b/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java @@ -1,49 +1,49 @@ -package bjc.utils.ioutils.format;
-
-/**
- * A collection of the modifiers attached to a CL format directive.
- *
- * @author EVE
- *
- */
-public class CLModifiers {
- /**
- * Whether the at mod is on.
- */
- public final boolean atMod;
- /**
- * Whether the colon mod is on.
- */
- public final boolean colonMod;
-
- /**
- * Create a new set of CL modifiers.
- *
- * @param at
- * The state of the at mod.
- * @param colon
- * The state of the colon mod.
- */
- public CLModifiers(boolean at, boolean colon) {
- atMod = at;
- colonMod = colon;
- }
-
- /**
- * Create a set of modifiers from a modifier string.
- *
- * @param modString
- * The string to parse modifiers from.
- * @return A set of modifiers matching the string.
- */
- public static CLModifiers fromString(String modString) {
- boolean atMod = false;
- boolean colonMod = false;
- if(modString != null) {
- atMod = modString.contains("@");
- colonMod = modString.contains(":");
- }
-
- return new CLModifiers(atMod, colonMod);
- }
+package bjc.utils.ioutils.format; + +/** + * A collection of the modifiers attached to a CL format directive. + * + * @author EVE + * + */ +public class CLModifiers { + /** + * Whether the at mod is on. + */ + public final boolean atMod; + /** + * Whether the colon mod is on. + */ + public final boolean colonMod; + + /** + * Create a new set of CL modifiers. + * + * @param at + * The state of the at mod. + * @param colon + * The state of the colon mod. + */ + public CLModifiers(boolean at, boolean colon) { + atMod = at; + colonMod = colon; + } + + /** + * Create a set of modifiers from a modifier string. + * + * @param modString + * The string to parse modifiers from. + * @return A set of modifiers matching the string. + */ + public static CLModifiers fromString(String modString) { + boolean atMod = false; + boolean colonMod = false; + if(modString != null) { + atMod = modString.contains("@"); + colonMod = modString.contains(":"); + } + + return new CLModifiers(atMod, colonMod); + } }
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java b/base/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java index 52b2e40..de093dd 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java +++ b/base/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java @@ -61,12 +61,12 @@ public class IterationDirective implements Directive { } int numItr = 0; - + if(mods.atMod && mods.colonMod) { do { if(numItr > maxItr) break; numItr += 1; - + if(!(iter instanceof Iterable<?>)) { throw new IllegalFormatConversionException('{', iter.getClass()); } @@ -76,14 +76,14 @@ public class IterationDirective implements Directive { Tape<Object> nParams = new SingleTape<>(nitr); fmt.doFormatString(frmt, sb, nParams); - + iter = tParams.right(); } while(tParams.position() < tParams.size()); } else if(mods.atMod) { while(tParams.position() < tParams.size()) { if(numItr > maxItr) break; numItr += 1; - + fmt.doFormatString(frmt, sb, tParams); } } else if(mods.colonMod) { @@ -97,7 +97,7 @@ public class IterationDirective implements Directive { for(Object obj : itr) { if(numItr > maxItr) break; numItr += 1; - + if(!(obj instanceof Iterable<?>)) { throw new IllegalFormatConversionException('{', obj.getClass()); } @@ -121,7 +121,7 @@ public class IterationDirective implements Directive { while(nParams.position() < nParams.size()) { if(numItr > maxItr) break; numItr += 1; - + fmt.doFormatString(frmt, sb, nParams); } } diff --git a/base/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java b/base/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java index ea04781..e77ab35 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java +++ b/base/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java @@ -9,8 +9,8 @@ import java.util.regex.Matcher; public class LiteralDirective implements Directive { - private char directive; - private String lit; + private char directive; + private String lit; public LiteralDirective(String lit, char directive) { this.directive = directive; diff --git a/base/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java b/base/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java index 98d6c16..b65e3cd 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java +++ b/base/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java @@ -15,8 +15,8 @@ public class NumberDirective extends GeneralNumberDirective { this.radix = radix; } - private int argidx; - private int radix; + private int argidx; + private int radix; @Override public void format(StringBuffer sb, Object item, CLModifiers mods, CLParameters params, Tape<Object> tParams, diff --git a/base/src/main/java/bjc/utils/math/Dual.java b/base/src/main/java/bjc/utils/math/Dual.java index e571519..81c9819 100644 --- a/base/src/main/java/bjc/utils/math/Dual.java +++ b/base/src/main/java/bjc/utils/math/Dual.java @@ -10,11 +10,11 @@ public class Dual { /** * The real part of the dual number. */ - public double real; + public double real; /** * The dual part of the dual number. */ - public double dual; + public double dual; /** * Create a new dual with both parts zero. diff --git a/base/src/main/java/bjc/utils/math/DualExpr.java b/base/src/main/java/bjc/utils/math/DualExpr.java index 8c73f34..947b00c 100644 --- a/base/src/main/java/bjc/utils/math/DualExpr.java +++ b/base/src/main/java/bjc/utils/math/DualExpr.java @@ -1,326 +1,326 @@ -package bjc.utils.math;
-
-/**
- * Represents an expression using dual numbers.
- *
- * Useful for automatically differentiating expressions.
- */
-public class DualExpr {
- /**
- * Represents the various types of dual expressions.
- */
- public static enum ExprType {
- /**
- * A fixed number.
- */
- CONSTANT,
- /**
- * An addition operation.
- */
- ADDITION,
- /**
- * A subtraction operation.
- */
- SUBTRACTION,
- /**
- * A multiplication operation.
- */
- MULTIPLICATION,
- /**
- * A division operation.
- */
- DIVISION,
- /**
- * A sine operation.
- */
- SIN,
- /**
- * A cosine operation.
- */
- COS,
- /**
- * An exponential function.
- */
- EXPONENTIAL,
- /**
- * A logarithm function.
- */
- LOGARITHM,
- /**
- * A power operation.
- */
- POWER,
- /**
- * An absolute value.
- */
- ABSOLUTE
- }
-
- /**
- * The type of the expression.
- */
- public final DualExpr.ExprType type;
-
- /**
- * The dual number value, for constants.
- */
- public Dual number;
-
- /**
- * The left (or first) part of the expression.
- */
- public DualExpr left;
- /**
- * The right (or second) part of the expression.
- */
- public DualExpr right;
-
- /**
- * The power to use, for power operations.
- */
- public int power;
-
- /**
- * Create a new constant dual number.
- *
- * @param num
- * The value of the dual number.
- */
- public DualExpr(Dual num) {
- this.type = ExprType.CONSTANT;
-
- number = num;
- }
-
- /**
- * Create a new unary dual number.
- *
- * @param type
- * The type of operation to perform.
- * @param val
- * The parameter to the value.
- */
- public DualExpr(DualExpr.ExprType type, DualExpr val) {
- this.type = type;
-
- left = val;
- }
-
- /**
- * Create a new binary dual number.
- *
- * @param type
- * The type of operation to perform.
- * @param left
- * The left hand side of the expression.
- * @param right
- * The right hand side of the expression.
- */
- public DualExpr(DualExpr.ExprType type, DualExpr left, DualExpr right) {
- this.type = type;
-
- this.left = left;
- this.right = right;
- }
-
- /**
- * Create a new power expression.
- *
- * @param left
- * The expression to raise.
- * @param power
- * The power to raise it by.
- */
- public DualExpr(DualExpr left, int power) {
- this.type = ExprType.POWER;
-
- this.left = left;
- this.power = power;
- }
-
- /**
- * Evaluate an expression to a number.
- *
- * Uses the rules provided in
- * https://en.wikipedia.org/wiki/Automatic_differentiation
- *
- * @return The evaluated expression.
- */
- public Dual evaluate() {
- /* The evaluated dual numbers. */
- Dual lval, rval;
-
- /* Perform the right operation for each type. */
- switch(type) {
- case CONSTANT:
- return number;
- case ADDITION:
- lval = left.evaluate();
- rval = right.evaluate();
-
- return new Dual(lval.real + rval.real, lval.dual + rval.dual);
- case SUBTRACTION:
- lval = left.evaluate();
- rval = right.evaluate();
-
- return new Dual(lval.real - rval.real, lval.dual - rval.dual);
- case MULTIPLICATION:
- lval = left.evaluate();
- rval = right.evaluate();
-
- {
- double lft = lval.dual * rval.real;
- double rght = lval.real * rval.dual;
-
- return new Dual(lval.real * rval.real, lft + rght);
- }
- case DIVISION:
- lval = left.evaluate();
- rval = right.evaluate();
-
- {
- if(rval.real == 0) {
- throw new IllegalArgumentException("ERROR: Attempted to divide by zero.");
- }
-
- double lft = lval.dual * rval.real;
- double rght = lval.real * rval.dual;
-
- double val = (lft - rght) / (rval.real * rval.real);
-
- return new Dual(lval.real / rval.real, val);
- }
- case SIN:
- lval = left.evaluate();
-
- return new Dual(Math.sin(lval.real), lval.dual * Math.cos(lval.real));
- case COS:
- lval = left.evaluate();
-
- return new Dual(Math.cos(lval.real), -lval.dual * Math.sin(lval.real));
- case EXPONENTIAL:
- lval = left.evaluate();
-
- {
- double val = Math.exp(lval.real);
-
- return new Dual(val, lval.dual * val);
- }
- case LOGARITHM:
- lval = left.evaluate();
-
- if(lval.real <= 0) {
- throw new IllegalArgumentException("ERROR: Attempted to take non-positive log.");
- }
-
- return new Dual(Math.log(lval.real), lval.dual / lval.real);
- case POWER:
- lval = left.evaluate();
-
- if(lval.real == 0) {
- throw new IllegalArgumentException("ERROR: Raising zero to a power.");
- }
-
- {
- double rl = Math.pow(lval.real, power);
-
- double lft = Math.pow(lval.real, power - 1);
-
- return new Dual(rl, power * lft * lval.dual);
- }
- case ABSOLUTE:
- lval = left.evaluate();
-
- return new Dual(Math.abs(lval.real), lval.dual * Math.signum(lval.real));
- default:
- String msg = "ERROR: Unknown expression type %s";
-
- throw new IllegalArgumentException(String.format(msg, type));
- }
- }
-
- @Override
- public String toString() {
- switch(type) {
- case ABSOLUTE:
- return String.format("abs(%s)", left.toString());
- case ADDITION:
- return String.format("(%s + %s)", left.toString(), right.toString());
- case CONSTANT:
- return String.format("%s", number.toString());
- case COS:
- return String.format("cos(%s)", left.toString());
- case DIVISION:
- return String.format("(%s / %s)", left.toString(), right.toString());
- case EXPONENTIAL:
- return String.format("exp(%s)", left.toString());
- case LOGARITHM:
- return String.format("log(%s)", left.toString());
- case MULTIPLICATION:
- return String.format("(%s * %s)", left.toString(), right.toString());
- case POWER:
- return String.format("(%s ^ %d)", left.toString(), power);
- case SIN:
- return String.format("sin(%s)", left.toString());
- case SUBTRACTION:
- return String.format("(%s - %s)", left.toString(), right.toString());
- default:
- return String.format("UNKNOWN_EXPR");
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + ((left == null) ? 0 : left.hashCode());
- result = prime * result + ((number == null) ? 0 : number.hashCode());
- result = prime * result + power;
- result = prime * result + ((right == null) ? 0 : right.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(getClass() != obj.getClass()) return false;
-
- DualExpr other = (DualExpr) obj;
-
- if(type != other.type) {
- return false;
- }
-
- if(left == null) {
- if(other.left != null) {
- return false;
- }
- } else if(!left.equals(other.left)) {
- return false;
- }
-
- if(number == null) {
- if(other.number != null) return false;
- } else if(!number.equals(other.number)) {
- return false;
- }
-
- if(power != other.power) {
- return false;
- }
-
- if(right == null) {
- if(other.right != null) {
- return false;
- }
- } else if(!right.equals(other.right)) {
- return false;
- }
-
- return true;
- }
+package bjc.utils.math; + +/** + * Represents an expression using dual numbers. + * + * Useful for automatically differentiating expressions. + */ +public class DualExpr { + /** + * Represents the various types of dual expressions. + */ + public static enum ExprType { + /** + * A fixed number. + */ + CONSTANT, + /** + * An addition operation. + */ + ADDITION, + /** + * A subtraction operation. + */ + SUBTRACTION, + /** + * A multiplication operation. + */ + MULTIPLICATION, + /** + * A division operation. + */ + DIVISION, + /** + * A sine operation. + */ + SIN, + /** + * A cosine operation. + */ + COS, + /** + * An exponential function. + */ + EXPONENTIAL, + /** + * A logarithm function. + */ + LOGARITHM, + /** + * A power operation. + */ + POWER, + /** + * An absolute value. + */ + ABSOLUTE + } + + /** + * The type of the expression. + */ + public final DualExpr.ExprType type; + + /** + * The dual number value, for constants. + */ + public Dual number; + + /** + * The left (or first) part of the expression. + */ + public DualExpr left; + /** + * The right (or second) part of the expression. + */ + public DualExpr right; + + /** + * The power to use, for power operations. + */ + public int power; + + /** + * Create a new constant dual number. + * + * @param num + * The value of the dual number. + */ + public DualExpr(Dual num) { + this.type = ExprType.CONSTANT; + + number = num; + } + + /** + * Create a new unary dual number. + * + * @param type + * The type of operation to perform. + * @param val + * The parameter to the value. + */ + public DualExpr(DualExpr.ExprType type, DualExpr val) { + this.type = type; + + left = val; + } + + /** + * Create a new binary dual number. + * + * @param type + * The type of operation to perform. + * @param left + * The left hand side of the expression. + * @param right + * The right hand side of the expression. + */ + public DualExpr(DualExpr.ExprType type, DualExpr left, DualExpr right) { + this.type = type; + + this.left = left; + this.right = right; + } + + /** + * Create a new power expression. + * + * @param left + * The expression to raise. + * @param power + * The power to raise it by. + */ + public DualExpr(DualExpr left, int power) { + this.type = ExprType.POWER; + + this.left = left; + this.power = power; + } + + /** + * Evaluate an expression to a number. + * + * Uses the rules provided in + * https://en.wikipedia.org/wiki/Automatic_differentiation + * + * @return The evaluated expression. + */ + public Dual evaluate() { + /* The evaluated dual numbers. */ + Dual lval, rval; + + /* Perform the right operation for each type. */ + switch(type) { + case CONSTANT: + return number; + case ADDITION: + lval = left.evaluate(); + rval = right.evaluate(); + + return new Dual(lval.real + rval.real, lval.dual + rval.dual); + case SUBTRACTION: + lval = left.evaluate(); + rval = right.evaluate(); + + return new Dual(lval.real - rval.real, lval.dual - rval.dual); + case MULTIPLICATION: + lval = left.evaluate(); + rval = right.evaluate(); + + { + double lft = lval.dual * rval.real; + double rght = lval.real * rval.dual; + + return new Dual(lval.real * rval.real, lft + rght); + } + case DIVISION: + lval = left.evaluate(); + rval = right.evaluate(); + + { + if(rval.real == 0) { + throw new IllegalArgumentException("ERROR: Attempted to divide by zero."); + } + + double lft = lval.dual * rval.real; + double rght = lval.real * rval.dual; + + double val = (lft - rght) / (rval.real * rval.real); + + return new Dual(lval.real / rval.real, val); + } + case SIN: + lval = left.evaluate(); + + return new Dual(Math.sin(lval.real), lval.dual * Math.cos(lval.real)); + case COS: + lval = left.evaluate(); + + return new Dual(Math.cos(lval.real), -lval.dual * Math.sin(lval.real)); + case EXPONENTIAL: + lval = left.evaluate(); + + { + double val = Math.exp(lval.real); + + return new Dual(val, lval.dual * val); + } + case LOGARITHM: + lval = left.evaluate(); + + if(lval.real <= 0) { + throw new IllegalArgumentException("ERROR: Attempted to take non-positive log."); + } + + return new Dual(Math.log(lval.real), lval.dual / lval.real); + case POWER: + lval = left.evaluate(); + + if(lval.real == 0) { + throw new IllegalArgumentException("ERROR: Raising zero to a power."); + } + + { + double rl = Math.pow(lval.real, power); + + double lft = Math.pow(lval.real, power - 1); + + return new Dual(rl, power * lft * lval.dual); + } + case ABSOLUTE: + lval = left.evaluate(); + + return new Dual(Math.abs(lval.real), lval.dual * Math.signum(lval.real)); + default: + String msg = "ERROR: Unknown expression type %s"; + + throw new IllegalArgumentException(String.format(msg, type)); + } + } + + @Override + public String toString() { + switch(type) { + case ABSOLUTE: + return String.format("abs(%s)", left.toString()); + case ADDITION: + return String.format("(%s + %s)", left.toString(), right.toString()); + case CONSTANT: + return String.format("%s", number.toString()); + case COS: + return String.format("cos(%s)", left.toString()); + case DIVISION: + return String.format("(%s / %s)", left.toString(), right.toString()); + case EXPONENTIAL: + return String.format("exp(%s)", left.toString()); + case LOGARITHM: + return String.format("log(%s)", left.toString()); + case MULTIPLICATION: + return String.format("(%s * %s)", left.toString(), right.toString()); + case POWER: + return String.format("(%s ^ %d)", left.toString(), power); + case SIN: + return String.format("sin(%s)", left.toString()); + case SUBTRACTION: + return String.format("(%s - %s)", left.toString(), right.toString()); + default: + return String.format("UNKNOWN_EXPR"); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + ((left == null) ? 0 : left.hashCode()); + result = prime * result + ((number == null) ? 0 : number.hashCode()); + result = prime * result + power; + result = prime * result + ((right == null) ? 0 : right.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + DualExpr other = (DualExpr) obj; + + if(type != other.type) { + return false; + } + + if(left == null) { + if(other.left != null) { + return false; + } + } else if(!left.equals(other.left)) { + return false; + } + + if(number == null) { + if(other.number != null) return false; + } else if(!number.equals(other.number)) { + return false; + } + + if(power != other.power) { + return false; + } + + if(right == null) { + if(other.right != null) { + return false; + } + } else if(!right.equals(other.right)) { + return false; + } + + return true; + } }
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/math/NumberUtils.java b/base/src/main/java/bjc/utils/math/NumberUtils.java index 53446ac..3c3ca02 100644 --- a/base/src/main/java/bjc/utils/math/NumberUtils.java +++ b/base/src/main/java/bjc/utils/math/NumberUtils.java @@ -428,7 +428,7 @@ public class NumberUtils { /* @TODO Should we have some way to specify how to pad? */ StringBuilder pad = new StringBuilder(); - + if(work.length() < mincols) { for(int i = work.length(); i < mincols; i++) { pad.append(padchar); diff --git a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java index e045222..31966d7 100644 --- a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java +++ b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java @@ -14,34 +14,33 @@ class DoubleMatcher { /* * Unit pieces. */ - private static final String rDecDigits = getRegex("fpDigits"); - private static final String rHexDigits = getRegex("fpHexDigits"); - private static final String rExponent = applyFormat("fpExponent", getRegex("fpExponent"), rDecDigits); + private static final String rDecDigits = getRegex("fpDigits"); + private static final String rHexDigits = getRegex("fpHexDigits"); + private static final String rExponent = applyFormat("fpExponent", getRegex("fpExponent"), rDecDigits); /* * Decimal floating point numbers. */ - private static final String rSimpleDec = applyFormat("fpDecimalDecimal", rDecDigits, rExponent); - private static final String rSimpleIntDec = applyFormat("fpDecimalInteger", rDecDigits, rExponent); + private static final String rSimpleDec = applyFormat("fpDecimalDecimal", rDecDigits, rExponent); + private static final String rSimpleIntDec = applyFormat("fpDecimalInteger", rDecDigits, rExponent); /* * Hex floating point numbers. */ - private static final String rHexInt = applyFormat("fpHexInteger", rHexDigits); - private static final String rHexDec = applyFormat("fpHexDecimal", rHexDigits); - private static final String rHexLead = applyFormat("fpHexLeader", rHexInt, rHexDec); - private static final String rHexString = applyFormat("fpHexString", rHexLead, rDecDigits); + private static final String rHexInt = applyFormat("fpHexInteger", rHexDigits); + private static final String rHexDec = applyFormat("fpHexDecimal", rHexDigits); + private static final String rHexLead = applyFormat("fpHexLeader", rHexInt, rHexDec); + private static final String rHexString = applyFormat("fpHexString", rHexLead, rDecDigits); /* * Floating point components. */ - private static final String rFPLeader = getRegex("fpLeader"); - private static final String rFPNum = applyFormat("fpNumber", rSimpleIntDec, rSimpleDec, - rHexString); + private static final String rFPLeader = getRegex("fpLeader"); + private static final String rFPNum = applyFormat("fpNumber", rSimpleIntDec, rSimpleDec, rHexString); /* * Full double. */ - private static final String rDouble = applyFormat("fpDouble", rFPLeader, rFPNum); - public static final Pattern doubleLiteral = Pattern.compile("\\A" + rDouble + "\\Z"); + private static final String rDouble = applyFormat("fpDouble", rFPLeader, rFPNum); + public static final Pattern doubleLiteral = Pattern.compile("\\A" + rDouble + "\\Z"); } diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index 352ad04..7a78a6e 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -61,9 +61,9 @@ public class ShuntingYard<TokenType> { * Function that shunts tokens. */ private final class TokenShunter implements Consumer<String> { - private final IList<TokenType> output; - private final Deque<String> stack; - private final Function<String, TokenType> transformer; + private final IList<TokenType> output; + private final Deque<String> stack; + private final Function<String, TokenType> transformer; public TokenShunter(final IList<TokenType> outpt, final Deque<String> stack, final Function<String, TokenType> transformer) { @@ -181,8 +181,7 @@ public class ShuntingYard<TokenType> { */ if(operator == null) throw new NullPointerException("Operator must not be null"); - else if (precedence == null) - throw new NullPointerException("Precedence must not be null"); + else if(precedence == null) throw new NullPointerException("Precedence must not be null"); /* * Add the operator to the ones we handle @@ -231,8 +230,7 @@ public class ShuntingYard<TokenType> { */ if(input == null) throw new NullPointerException("Input must not be null"); - else if (transformer == null) - throw new NullPointerException("Transformer must not be null"); + else if(transformer == null) throw new NullPointerException("Transformer must not be null"); /* * Here's what we're handing back diff --git a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java index c995396..fb6fe8f 100644 --- a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java +++ b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java @@ -23,19 +23,19 @@ public class StringDescaper { /* * Patterns and pattern parts. */ - private static String rPossibleEscapeString = getRegex("possibleStringEscape"); - private static Pattern possibleEscapePatt = Pattern.compile(rPossibleEscapeString); + private static String rPossibleEscapeString = getRegex("possibleStringEscape"); + private static Pattern possibleEscapePatt = Pattern.compile(rPossibleEscapeString); - private static String rShortEscape = getRegex("shortFormStringEscape"); - private static String rOctalEscape = getRegex("octalStringEscape"); - private static String rUnicodeEscape = getRegex("unicodeStringEscape"); + private static String rShortEscape = getRegex("shortFormStringEscape"); + private static String rOctalEscape = getRegex("octalStringEscape"); + private static String rUnicodeEscape = getRegex("unicodeStringEscape"); - private String rEscapeString; - private Pattern escapePatt; + private String rEscapeString; + private Pattern escapePatt; - private Map<String, String> literalEscapes; + private Map<String, String> literalEscapes; private Map<Pattern, UnaryOperator<String>> specialEscapes; - + /** * Create a new customizable string escape remover. */ @@ -45,18 +45,17 @@ public class StringDescaper { specialEscapes = new HashMap<>(); /* Set up the hard-coded escapes. */ - rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)", - rShortEscape, rOctalEscape, rUnicodeEscape); - escapePatt = Pattern.compile(rEscapeString); + rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)", rShortEscape, rOctalEscape, rUnicodeEscape); + escapePatt = Pattern.compile(rEscapeString); } /** * Add a new literal escape. * * @param escape - * The custom escape to add. + * The custom escape to add. * @param val - * The value for the escape. + * The value for the escape. */ public void addLiteralEscape(String escape, String val) { if(literalEscapes.containsKey(escape)) { @@ -142,13 +141,13 @@ public class StringDescaper { /* * Prepare the buffer and escape finder. */ - final StringBuffer work = new StringBuffer(); + final StringBuffer work = new StringBuffer(); final Matcher possibleEscapeFinder = possibleEscapePatt.matcher(inp); - final Matcher escapeFinder = escapePatt.matcher(inp); + final Matcher escapeFinder = escapePatt.matcher(inp); /* Go through each escape. */ - while (possibleEscapeFinder.find()) { - if (!escapeFinder.find()) { + while(possibleEscapeFinder.find()) { + if(!escapeFinder.find()) { /* * Found a possible escape that isn't actually * an escape. @@ -195,7 +194,7 @@ public class StringDescaper { escapeRep = "\\"; break; default: - if (escapeSeq.startsWith("u")) { + if(escapeSeq.startsWith("u")) { /* Handle a unicode escape. */ escapeRep = handleUnicodeEscape(escapeSeq.substring(1)); } else if(escapeSeq.startsWith("O")) { diff --git a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java index 5a37596..72913db 100644 --- a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java +++ b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java @@ -90,8 +90,8 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> { private final Predicate<TokenType> operatorPredicate; - private final Predicate<TokenType> isSpecialOperator; - private final Function<TokenType, QueueFlattener<TokenType>> handleSpecialOperator; + private final Predicate<TokenType> isSpecialOperator; + private final Function<TokenType, QueueFlattener<TokenType>> handleSpecialOperator; /* * Create a new transformer diff --git a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java index 2a6c0fd..dba9b74 100644 --- a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java +++ b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java @@ -41,9 +41,9 @@ public class TokenUtils { private static Pattern possibleEscapePatt = Pattern.compile(rPossibleEscapeString); - private static String rShortEscape = getRegex("shortFormStringEscape"); - private static String rOctalEscape = getRegex("octalStringEscape"); - private static String rUnicodeEscape = getRegex("unicodeStringEscape"); + private static String rShortEscape = getRegex("shortFormStringEscape"); + private static String rOctalEscape = getRegex("octalStringEscape"); + private static String rUnicodeEscape = getRegex("unicodeStringEscape"); private static String rEscapeString = applyFormat("stringEscape", rShortEscape, rOctalEscape, rUnicodeEscape); diff --git a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java index 6d1ed64..3d279d8 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java @@ -27,7 +27,7 @@ public class IteratedDefine implements UnaryOperator<String> { * Whether or not to loop through the list of replacers, or just * repeat the last one. * @param replacers - * The set of replacement strings to use. + * The set of replacement strings to use. */ public IteratedDefine(Pattern pattern, boolean circular, String... replacers) { patt = pattern; diff --git a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java index c3496a8..032c33e 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java @@ -10,16 +10,16 @@ import java.util.regex.Pattern; * @author Ben Culkin */ public class SimpleDefine implements UnaryOperator<String> { - private Pattern patt; - private String repl; + private Pattern patt; + private String repl; /** * Create a new simple define. * * @param pattern - * The pattern to match against. + * The pattern to match against. * @param replace - * The text to use as a replacement. + * The text to use as a replacement. */ public SimpleDefine(Pattern pattern, String replace) { patt = pattern; diff --git a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java index 0fe998d..e89ba08 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java @@ -47,8 +47,8 @@ public class DelimiterGroup<T> { /* * The token that opened the group, and any opening parameters. */ - private final T opener; - private final T[] params; + private final T opener; + private final T[] params; /** * Create a new instance of a delimiter group. @@ -148,8 +148,8 @@ public class DelimiterGroup<T> { final ITree<T> res = new Tree<>(chars.contents); /* - * Add either the contents of the current group, - * or subgroups if they're there. + * Add either the contents of the current group, or + * subgroups if they're there. */ if(contents.isEmpty()) { currentGroup.forEach(res::addChild); @@ -261,14 +261,12 @@ public class DelimiterGroup<T> { * open one. */ public IPair<T, T[]> doesOpen(final T marker) { - if (openDelimiters.containsKey(marker)) - return new Pair<>(openDelimiters.get(marker), null); + if(openDelimiters.containsKey(marker)) return new Pair<>(openDelimiters.get(marker), null); for(final Function<T, IPair<T, T[]>> pred : predOpeners) { final IPair<T, T[]> par = pred.apply(marker); - if (par.getLeft() != null) - return par; + if(par.getLeft() != null) return par; } return new Pair<>(null, null); @@ -329,20 +327,19 @@ public class DelimiterGroup<T> { * The name of the delimiter group */ public DelimiterGroup(final T name) { - if (name == null) - throw new NullPointerException("Group name must not be null"); + if(name == null) throw new NullPointerException("Group name must not be null"); groupName = name; - openDelimiters = new HashMap<>(); + openDelimiters = new HashMap<>(); nestedOpenDelimiters = new HashMap<>(); closingDelimiters = new HashSet<>(); topLevelExclusions = new HashSet<>(); - groupExclusions = new HashSet<>(); + groupExclusions = new HashSet<>(); - subgroups = new HashMap<>(); + subgroups = new HashMap<>(); impliedSubgroups = new HashMap<>(); predOpeners = new LinkedList<>(); @@ -359,10 +356,10 @@ public class DelimiterGroup<T> { public final void addClosing(final T... closers) { final List<T> closerList = Arrays.asList(closers); - for (final T closer : closerList) { - if (closer == null) { + for(final T closer : closerList) { + if(closer == null) { throw new NullPointerException("Closing delimiter must not be null"); - } else if (closer.equals("")) { + } else if(closer.equals("")) { /* * We can do this because equals works on * arbitrary objects, not just those of the same @@ -384,10 +381,10 @@ public class DelimiterGroup<T> { */ @SafeVarargs public final void addTopLevelForbid(final T... exclusions) { - for (final T exclusion : exclusions) { - if (exclusion == null) { + for(final T exclusion : exclusions) { + if(exclusion == null) { throw new NullPointerException("Exclusion must not be null"); - } else if (exclusion.equals("")) { + } else if(exclusion.equals("")) { /* * We can do this because equals works on * arbitrary objects, not just those of the same @@ -408,10 +405,10 @@ public class DelimiterGroup<T> { */ @SafeVarargs public final void addGroupForbid(final T... exclusions) { - for (final T exclusion : exclusions) { - if (exclusion == null) { + for(final T exclusion : exclusions) { + if(exclusion == null) { throw new NullPointerException("Exclusion must not be null"); - } else if (exclusion.equals("")) { + } else if(exclusion.equals("")) { /* * We can do this because equals works on * arbitrary objects, not just those of the same @@ -434,8 +431,7 @@ public class DelimiterGroup<T> { * The priority of this sub-group. */ public void addSubgroup(final T subgroup, final int priority) { - if (subgroup == null) - throw new NullPointerException("Subgroup marker must not be null"); + if(subgroup == null) throw new NullPointerException("Subgroup marker must not be null"); subgroups.put(subgroup, priority); } @@ -450,10 +446,9 @@ public class DelimiterGroup<T> { * The group opened by the marker. */ public void addOpener(final T opener, final T group) { - if (opener == null) + if(opener == null) throw new NullPointerException("Opener must not be null"); - else if (group == null) - throw new NullPointerException("Group to open must not be null"); + else if(group == null) throw new NullPointerException("Group to open must not be null"); openDelimiters.put(opener, group); } @@ -468,9 +463,9 @@ public class DelimiterGroup<T> { * The group opened by the marker. */ public void addNestedOpener(final T opener, final T group) { - if (opener == null) { + if(opener == null) { throw new NullPointerException("Opener must not be null"); - } else if (group == null) { + } else if(group == null) { throw new NullPointerException("Group to open must not be null"); } @@ -487,13 +482,13 @@ public class DelimiterGroup<T> { * The subgroup to imply. */ public void implySubgroup(final T closer, final T subgroup) { - if (closer == null) { + if(closer == null) { throw new NullPointerException("Closer must not be null"); - } else if (subgroup == null) { + } else if(subgroup == null) { throw new NullPointerException("Subgroup must not be null"); - } else if (!closingDelimiters.contains(closer)) { + } else if(!closingDelimiters.contains(closer)) { throw new IllegalArgumentException(String.format("No closing delimiter '%s' defined", closer)); - } else if (!subgroups.containsKey(subgroup)) { + } else if(!subgroups.containsKey(subgroup)) { throw new IllegalArgumentException(String.format("No subgroup '%s' defined", subgroup)); } diff --git a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java index 6aa3cc9..ff4b348 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java @@ -87,9 +87,9 @@ public class SequenceDelimiter<T> { */ public ITree<T> delimitSequence(final SequenceCharacteristics<T> chars, @SuppressWarnings("unchecked") final T... seq) throws DelimiterException { - if (initialGroup == null) { + if(initialGroup == null) { throw new NullPointerException("Initial group must be specified."); - } else if (chars == null) { + } else if(chars == null) { throw new NullPointerException("Sequence characteristics must not be null"); } @@ -110,10 +110,10 @@ public class SequenceDelimiter<T> { /* Map of who forbid what for debugging purposes. */ final IMap<T, T> whoForbid = new PushdownMap<>(); - /* + /* * Process each member of the sequence. */ - for (int i = 0; i < seq.length; i++) { + for(int i = 0; i < seq.length; i++) { final T tok = seq[i]; /* Check if this token could open a group. */ @@ -233,8 +233,8 @@ public class SequenceDelimiter<T> { if(groupStack.size() > 1) { final DelimiterGroup<T>.OpenGroup group = groupStack.top(); - final String closingDelims = StringUtils.toEnglishList( - group.getNestingExclusions().toArray(), false); + final String closingDelims = StringUtils.toEnglishList(group.getNestingExclusions().toArray(), + false); final String ctxList = StringUtils.toEnglishList(groupStack.toArray(), "then"); @@ -270,7 +270,7 @@ public class SequenceDelimiter<T> { * The delimiter group. */ public void addGroup(final DelimiterGroup<T> group) { - if (group == null) { + if(group == null) { throw new NullPointerException("Group must not be null"); } diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java index 0a46edb..cc69221 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java @@ -30,9 +30,9 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { super(null, keepDelims); /* Use linked hash-sets to keep items in insertion order. */ - simpleDelimiters = new LinkedHashSet<>(); + simpleDelimiters = new LinkedHashSet<>(); multipleDelimiters = new LinkedHashSet<>(); - rRawDelimiters = new LinkedHashSet<>(); + rRawDelimiters = new LinkedHashSet<>(); } /** diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java index b38a5c3..3e58629 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java @@ -14,7 +14,7 @@ import bjc.utils.funcdata.IList; * */ public class ExcludingTokenSplitter implements TokenSplitter { - private final Set<String> literalExclusions; + private final Set<String> literalExclusions; private final IList<Predicate<String>> predExclusions; private final TokenSplitter spliter; |
