summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
commitdf94066e3af02ff02d5ab4d033a3d603f743234c (patch)
tree168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
parentae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff)
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java')
-rw-r--r--base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java67
1 files changed, 34 insertions, 33 deletions
diff --git a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
index 7c5205b..9e4bbb6 100644
--- a/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
+++ b/base/src/main/java/bjc/utils/ioutils/RuleBasedConfigReader.java
@@ -22,30 +22,30 @@ import bjc.utils.funcdata.IMap;
* @author ben
*
* @param <E>
- * The type of the state object to use
+ * The type of the state object to use
*
*/
public class RuleBasedConfigReader<E> {
- /* Function to execute when starting a rule.
- * Takes the tokenizer, and a pair of the read token and application state
+ /*
+ * Function to execute when starting a rule. Takes the tokenizer, and a
+ * pair of the read token and application state
*/
private BiConsumer<FunctionalStringTokenizer, IPair<String, E>> start;
/*
- * Function to use when continuing a rule
- * Takes a tokenizer and application state
+ * Function to use when continuing a rule Takes a tokenizer and
+ * application state
*/
private BiConsumer<FunctionalStringTokenizer, E> continueRule;
/*
- * Function to use when ending a rule
- * Takes an application state
+ * Function to use when ending a rule Takes an application state
*/
private Consumer<E> end;
/*
- * Map of pragma names to pragma actions
- * Pragma actions are functions taking a tokenizer and application state
+ * Map of pragma names to pragma actions Pragma actions are functions
+ * taking a tokenizer and application state
*/
private final IMap<String, BiConsumer<FunctionalStringTokenizer, E>> pragmas;
@@ -53,11 +53,11 @@ public class RuleBasedConfigReader<E> {
* 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<FunctionalStringTokenizer, IPair<String, E>> start,
final BiConsumer<FunctionalStringTokenizer, E> continueRule, final Consumer<E> end) {
@@ -72,22 +72,23 @@ public class RuleBasedConfigReader<E> {
* 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<FunctionalStringTokenizer, E> action) {
- if (name == null) throw new NullPointerException("Pragma name must not be null");
- else if (action == null) throw new NullPointerException("Pragma action must not be null");
+ if(name == null)
+ throw new NullPointerException("Pragma name must not be 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) {
// 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)
+ else if(continueRule == null)
throw new InputMismatchException("Rule continuation not supported for current grammar");
/*
@@ -100,7 +101,7 @@ public class RuleBasedConfigReader<E> {
/*
* Ignore blank line without an open rule
*/
- if (isRuleOpen == false)
+ if(isRuleOpen == false)
/*
* Do nothing
*/
@@ -109,7 +110,7 @@ public class RuleBasedConfigReader<E> {
/*
* Nothing happens on rule end
*/
- if (end != null) {
+ if(end != null) {
/*
* Process the rule ending
*/
@@ -127,13 +128,13 @@ public class RuleBasedConfigReader<E> {
* 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
@@ -143,7 +144,7 @@ public class RuleBasedConfigReader<E> {
/*
* 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
@@ -157,17 +158,17 @@ public class RuleBasedConfigReader<E> {
/*
* 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")) {
/*
* Continue the rule
*/
@@ -191,7 +192,7 @@ public class RuleBasedConfigReader<E> {
* 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<FunctionalStringTokenizer, E> continueRule) {
this.continueRule = continueRule;
@@ -201,7 +202,7 @@ public class RuleBasedConfigReader<E> {
* 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<E> end) {
this.end = end;
@@ -211,10 +212,10 @@ public class RuleBasedConfigReader<E> {
* 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<FunctionalStringTokenizer, IPair<String, E>> start) {
- if (start == null) throw new NullPointerException("Action on rule start must be non-null");
+ if(start == null) throw new NullPointerException("Action on rule start must be non-null");
this.start = start;
}
@@ -233,7 +234,7 @@ public class RuleBasedConfigReader<E> {
/*
* Handle pragmas
*/
- if (nextToken.equals("pragma")) {
+ if(nextToken.equals("pragma")) {
/*
* Get the pragma name
*/
@@ -249,7 +250,7 @@ public class RuleBasedConfigReader<E> {
/*
* Make sure input is correct
*/
- if (isRuleOpen == true)
+ if(isRuleOpen == true)
throw new InputMismatchException("Nested rules are currently not supported");
/*