From 01cb9f504c860bc1c037a44f3a76bf342a293d46 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 22 Mar 2016 12:28:35 -0400 Subject: General formatting cleanup and documentation update --- .../utils/parserutils/RuleBasedConfigReader.java | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java') 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 963437e..12f6891 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedConfigReader.java @@ -17,8 +17,8 @@ import bjc.utils.funcdata.FunctionalStringTokenizer; * * @author ben * - * @param The - * type of the state object to use + * @param + * The type of the state object to use */ public class RuleBasedConfigReader { private BiConsumer> startRule; @@ -48,11 +48,28 @@ public class RuleBasedConfigReader { this.pragmas = new HashMap<>(); } + /** + * Add a pragma to this reader + * + * @param pragName + * The name of the pragma to add + * @param pragAct + * The function to execute when this pragma is read + */ public void addPragma(String pragName, BiConsumer pragAct) { pragmas.put(pragName, pragAct); } + /** + * Run a stream through this reader + * + * @param is + * The stream to get input + * @param initState + * The initial state of the reader + * @return The final state of the reader + */ public E fromStream(InputStream is, E initState) { Scanner scn = new Scanner(is); @@ -68,8 +85,8 @@ public class RuleBasedConfigReader { continueRule.accept(new FunctionalStringTokenizer( ln.substring(1), " "), stat); } else { - FunctionalStringTokenizer stk = new FunctionalStringTokenizer( - ln, " "); + FunctionalStringTokenizer stk = + new FunctionalStringTokenizer(ln, " "); String nxtToken = stk.nextToken(); if (nxtToken.equals("#")) { @@ -82,8 +99,7 @@ public class RuleBasedConfigReader { "Unknown pragma " + tk); }).accept(stk, stat); } else { - startRule.accept(stk, - new Pair(nxtToken, stat)); + startRule.accept(stk, new Pair<>(nxtToken, stat)); } } } @@ -93,15 +109,33 @@ public class RuleBasedConfigReader { return stat; } + /** + * Set the action to execute when continuing a rule + * + * @param continueRule + * The action to execute on continuation of a rule + */ public void setContinueRule( BiConsumer continueRule) { this.continueRule = continueRule; } + /** + * Set the action to execute when ending a rule + * + * @param endRule + * The action to execute on ending of a rule + */ public void setEndRule(Consumer endRule) { this.endRule = endRule; } + /** + * Set the action to execute when starting a rule + * + * @param startRule + * The action to execute on starting of a rule + */ public void setStartRule( BiConsumer> startRule) { this.startRule = startRule; -- cgit v1.2.3