summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java')
-rw-r--r--base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
index f7ddaff..3855f8f 100644
--- a/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
+++ b/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
@@ -1,57 +1,63 @@
package bjc.utils.components;
-import static bjc.utils.ioutils.RuleBasedReaderPragmas.buildInteger;
-import static bjc.utils.ioutils.RuleBasedReaderPragmas.buildStringCollapser;
-
import java.io.InputStream;
import bjc.utils.ioutils.RuleBasedConfigReader;
+import static bjc.utils.ioutils.RuleBasedReaderPragmas.buildInteger;
+import static bjc.utils.ioutils.RuleBasedReaderPragmas.buildStringCollapser;
+
/**
- * Read a component description from a file
+ * Read a component description from a file.
*
* @author ben
- *
*/
public class ComponentDescriptionFileParser {
- // The reader used to read in component descriptions
+ /* The reader used to read in component descriptions */
private static RuleBasedConfigReader<ComponentDescriptionState> reader;
- // Initialize the reader and its pragmas
+ /* Initialize the reader and its pragmas. */
static {
- // This reader works entirely off of pragmas, so no need to
- // handle
- // rules
+ /*
+ * This reader works entirely off of pragmas, so no need to
+ * handle rules.
+ */
reader = new RuleBasedConfigReader<>((tokenizer, statePair) -> {
- // Don't need to do anything on rule start
+ /* Don't need to do anything on rule start. */
}, (tokenizer, state) -> {
- // Don't need to do anything on rule continuation
+ /* Don't need to do anything on rule continuation. */
}, (state) -> {
- // Don't need to do anything on rule end
+ /* Don't need to do anything on rule end. */
});
+ /* Setup reader pragmas. */
setupReaderPragmas();
}
/**
- * Parse a component description from a stream
+ * Parse a component description from a stream.
*
* @param inputSource
- * The stream to parse from
- * @return The description parsed from the stream
+ * The stream to parse from.
+ *
+ * @return The description parsed from the stream.
*/
public static ComponentDescription fromStream(final InputStream inputSource) {
- if (inputSource == null) throw new NullPointerException("Input source must not be null");
+ if (inputSource == null) {
+ throw new NullPointerException("Input source must not be null");
+ }
- final ComponentDescriptionState readState = reader.fromStream(inputSource,
- new ComponentDescriptionState());
+ ComponentDescriptionState state = new ComponentDescriptionState();
+ /*
+ * This is valid, because the thing that is returned is the same
+ * reference we passed in.
+ */
+ reader.fromStream(inputSource, state);
- return readState.toDescription();
+ return state.toDescription();
}
- /*
- * Create all the pragmas the reader needs to function
- */
+ /* Create all the pragmas the reader needs to function. */
private static void setupReaderPragmas() {
reader.addPragma("name", buildStringCollapser("name", (name, state) -> state.setName(name)));