From 82951e37e10b282d9a7c89f4662990b64949c943 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 29 Feb 2016 10:41:17 -0500 Subject: General code cleanup --- .../utils/parserutils/RuleBasedConfigReader.java | 28 +++++++++++----------- .../java/bjc/utils/parserutils/ShuntingYard.java | 25 +++++++++---------- .../utils/parserutils/UnknownPragmaException.java | 19 +++++++++++++-- 3 files changed, 42 insertions(+), 30 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils') 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 1190281..d07d725 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java @@ -20,12 +20,12 @@ import bjc.utils.funcdata.FunctionalStringTokenizer; * type of the state object to use */ public class RuleBasedConfigReader { - private Map> pragmas; - private BiConsumer> startRule; private BiConsumer continueRule; private Consumer endRule; + private Map> pragmas; + /** * Create a new rule-based config reader * @@ -43,10 +43,15 @@ public class RuleBasedConfigReader { this.startRule = startRule; this.continueRule = continueRule; this.endRule = endRule; - + this.pragmas = new HashMap<>(); } + public void addPragma(String pragName, + BiConsumer pragAct) { + pragmas.put(pragName, pragAct); + } + public E fromStream(InputStream is, E initState) { Scanner scn = new Scanner(is); @@ -67,7 +72,7 @@ public class RuleBasedConfigReader { String nxtToken = stk.nextToken(); if (nxtToken.equals("#")) { - + // Do nothing, this is a comment } else if (nxtToken.equals("pragma")) { String tk = stk.nextToken(); @@ -87,16 +92,6 @@ public class RuleBasedConfigReader { return stat; } - public void addPragma(String pragName, - BiConsumer pragAct) { - pragmas.put(pragName, pragAct); - } - - public void setStartRule( - BiConsumer> startRule) { - this.startRule = startRule; - } - public void setContinueRule( BiConsumer continueRule) { this.continueRule = continueRule; @@ -105,4 +100,9 @@ public class RuleBasedConfigReader { public void setEndRule(Consumer endRule) { this.endRule = endRule; } + + public void setStartRule( + BiConsumer> startRule) { + this.startRule = startRule; + } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java index ace636e..8a036ce 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -19,7 +19,7 @@ import bjc.utils.funcdata.FunctionalList; */ public class ShuntingYard { - private static enum Operator implements IPrecedent { + public static enum Operator implements IPrecedent { ADD(1), DIVIDE(4), MULTIPLY(3), SUBTRACT(2); private final int precedence; @@ -39,9 +39,6 @@ public class ShuntingYard { } } - static { - } - /** * Holds all the shuntable operations */ @@ -59,6 +56,16 @@ public class ShuntingYard { ops.put("/", Operator.DIVIDE); } + /** + * Add an operator to the list of shuntable operators + * + * @param tok + * The token representing the operator + */ + public void addOp(String tok, int i) { + this.addOp(tok, IPrecedent.newSimplePrecedent(i)); + } + /** * Add an operator to the list of shuntable operators * @@ -127,14 +134,4 @@ public class ShuntingYard { public void removeOp(String tok) { ops.remove(tok); } - - /** - * Add an operator to the list of shuntable operators - * - * @param tok - * The token representing the operator - */ - public void addOp(String tok, int i) { - this.addOp(tok, IPrecedent.newSimplePrecedent(i)); - } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/UnknownPragmaException.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/UnknownPragmaException.java index fc97a44..88f38d4 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/UnknownPragmaException.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/UnknownPragmaException.java @@ -2,11 +2,26 @@ package bjc.utils.parserutils; import java.util.InputMismatchException; +/** + * Represents a error from encountering a unknown pragma + * + * @author ben + * + */ public class UnknownPragmaException extends InputMismatchException { + /** + * Version id for serialization + */ + private static final long serialVersionUID = -4277573484926638662L; + + /** + * Create a new exception with the given cause + * + * @param m + * The cause for throwing this exception + */ public UnknownPragmaException(String m) { super(m); } - private static final long serialVersionUID = -4277573484926638662L; - } -- cgit v1.2.3