From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../bjc/utils/ioutils/RuleBasedConfigReader.java | 86 ++++++++++++---------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java') diff --git a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java index 2ee25d1..88a3b81 100644 --- a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java +++ b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java @@ -22,7 +22,7 @@ import bjc.funcdata.IMap; * @author ben * * @param - * The type of the state object to use + * The type of the state object to use * */ public class RuleBasedConfigReader { @@ -58,14 +58,16 @@ public class RuleBasedConfigReader { * Create a new rule-based config reader * * @param start - * The action to fire when starting a rule + * The action to fire when starting a rule * @param continueRule - * The action to fire when continuing a rule + * The action to fire when continuing a rule * @param end - * The action to fire when ending a rule + * The action to fire when ending a rule */ - public RuleBasedConfigReader(final BiConsumer> start, - final BiConsumer continueRule, final Consumer end) { + public RuleBasedConfigReader( + final BiConsumer> start, + final BiConsumer continueRule, + final Consumer end) { this.start = start; this.continueRule = continueRule; this.end = end; @@ -77,25 +79,28 @@ public class RuleBasedConfigReader { * Add a pragma to this reader * * @param name - * The name of the pragma to add + * The name of the pragma to add * @param action - * The function to execute when this pragma is read + * The function to execute when this pragma is read */ - public void addPragma(final String name, final BiConsumer action) { - if(name == null) + public void addPragma(final String name, + final BiConsumer action) { + if (name == null) throw new NullPointerException("Pragma name must not be null"); - else if(action == null) + else if (action == null) throw new NullPointerException("Pragma action must not be null"); pragmas.put(name, action); } - private void continueRule(final E state, final boolean isRuleOpen, final String line) { + private void continueRule(final E state, final boolean isRuleOpen, + final String line) { // Make sure our input is correct - if(isRuleOpen == false) + if (isRuleOpen == false) throw new InputMismatchException("Cannot continue rule with no rule open"); - else if(continueRule == null) - throw new InputMismatchException("Rule continuation not supported for current grammar"); + else if (continueRule == null) + throw new InputMismatchException( + "Rule continuation not supported for current grammar"); /* * Accept the rule @@ -107,7 +112,7 @@ public class RuleBasedConfigReader { /* * Ignore blank line without an open rule */ - if(isRuleOpen == false) { + if (isRuleOpen == false) { /* * Do nothing */ @@ -117,7 +122,7 @@ public class RuleBasedConfigReader { /* * Nothing happens on rule end */ - if(end != null) { + if (end != null) { /* * Process the rule ending */ @@ -134,13 +139,14 @@ public class RuleBasedConfigReader { * Run a stream through this reader * * @param input - * The stream to get input + * The stream to get input * @param initialState - * The initial state of the reader + * The initial state of the reader * @return The final state of the reader */ public E fromStream(final InputStream input, final E initialState) { - if(input == null) throw new NullPointerException("Input stream must not be null"); + if (input == null) + throw new NullPointerException("Input stream must not be null"); /* * Application state: We're giving this back later @@ -150,7 +156,7 @@ public class RuleBasedConfigReader { /* * Prepare our input source */ - try(Scanner source = new Scanner(input)) { + try (Scanner source = new Scanner(input)) { source.useDelimiter("\n"); /* * This is true when a rule's open @@ -160,27 +166,28 @@ public class RuleBasedConfigReader { /* * Do something for every line of the file */ - source.forEachRemaining((line) -> { + source.forEachRemaining(line -> { /* * Skip comment lines */ - if(line.startsWith("#") || line.startsWith("//")) + if (line.startsWith("#") || line.startsWith("//")) /* * It's a comment */ return; - else if(line.equals("")) { + else if (line.equals("")) { /* * End the rule */ isRuleOpen.replace(endRule(state, isRuleOpen.getValue())); - } else if(line.startsWith("\t")) { + } else if (line.startsWith("\t")) { /* * Skip comment lines. */ - if(line.startsWith("#") || line.startsWith("//")) + if (line.startsWith("#") || line.startsWith("//")) /* - * It's a comment. */ + * It's a comment. + */ return; /* @@ -206,9 +213,10 @@ public class RuleBasedConfigReader { * Set the action to execute when continuing a rule * * @param continueRule - * The action to execute on continuation of a rule + * The action to execute on continuation of a rule */ - public void setContinueRule(final BiConsumer continueRule) { + public void + setContinueRule(final BiConsumer continueRule) { this.continueRule = continueRule; } @@ -216,7 +224,7 @@ public class RuleBasedConfigReader { * Set the action to execute when ending a rule * * @param end - * The action to execute on ending of a rule + * The action to execute on ending of a rule */ public void setEndRule(final Consumer end) { this.end = end; @@ -226,10 +234,12 @@ public class RuleBasedConfigReader { * Set the action to execute when starting a rule * * @param start - * The action to execute on starting of a rule + * The action to execute on starting of a rule */ - public void setStartRule(final BiConsumer> start) { - if(start == null) throw new NullPointerException("Action on rule start must be non-null"); + public void setStartRule( + final BiConsumer> start) { + if (start == null) + throw new NullPointerException("Action on rule start must be non-null"); this.start = start; } @@ -238,7 +248,8 @@ public class RuleBasedConfigReader { /* * Create the line tokenizer */ - final FunctionalStringTokenizer tokenizer = new FunctionalStringTokenizer(line, " "); + final FunctionalStringTokenizer tokenizer + = new FunctionalStringTokenizer(line, " "); /* * Get the initial token @@ -248,7 +259,7 @@ public class RuleBasedConfigReader { /* * Handle pragmas */ - if(nextToken.equals("pragma")) { + if (nextToken.equals("pragma")) { /* * Get the pragma name */ @@ -264,8 +275,9 @@ public class RuleBasedConfigReader { /* * Make sure input is correct */ - if(isRuleOpen == true) - throw new InputMismatchException("Nested rules are currently not supported"); + if (isRuleOpen == true) + throw new InputMismatchException( + "Nested rules are currently not supported"); /* * Start a rule -- cgit v1.2.3