diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/ioutils')
6 files changed, 115 insertions, 23 deletions
diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java index b1e82d7..36e0ac1 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/BoundBlockReader.java @@ -5,24 +5,52 @@ import java.io.IOException; import java.util.function.BooleanSupplier; import java.util.function.Supplier; +/** + * A block reader composed from functions. + * + * @author EVE + * + */ public class BoundBlockReader implements BlockReader { + /** + * A function that serves to close an I/O source. + * + * @author EVE + * + */ @FunctionalInterface public interface Closer { + /** + * Close the I/O source this is attached to. + * + * @throws IOException + * If something goes wrong + */ public void close() throws IOException; } - private BooleanSupplier checker; - private Supplier<Block> getter; - private Closer closer; + private BooleanSupplier checker; + private Supplier<Block> getter; + private Closer closer; private Block current; private int blockNo; + /** + * Create a new bound block reader. + * + * @param blockChecker + * Predicate for checking if a block is available + * @param blockGetter + * Function to retrieve a block + * @param blockCloser + * Function to close a block source + */ public BoundBlockReader(BooleanSupplier blockChecker, Supplier<Block> blockGetter, Closer blockCloser) { checker = blockChecker; - getter = blockGetter; - closer = blockCloser; + getter = blockGetter; + closer = blockCloser; blockNo = 0; } @@ -40,11 +68,11 @@ public class BoundBlockReader implements BlockReader { @Override public boolean nextBlock() { if(checker.getAsBoolean()) { - current = getter.get(); + current = getter.get(); blockNo += 1; return true; - } + } return false; } diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java index 0b43f7a..c575f05 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/FilteredBlockReader.java @@ -16,8 +16,8 @@ public class FilteredBlockReader implements BlockReader { * * Both have already been checked for the predicate. */ - private Block current; - private Block pending; + private Block current; + private Block pending; /* * Number of blocks that passed the predicate. @@ -39,8 +39,8 @@ public class FilteredBlockReader implements BlockReader { } public FilteredBlockReader(BlockReader src, Predicate<Block> predic, Consumer<Block> failAct) { - source = src; - pred = predic; + source = src; + pred = predic; failAction = failAct; blockNo = 0; @@ -60,11 +60,11 @@ public class FilteredBlockReader implements BlockReader { if(pred.test(pending)) { blockNo += 1; return true; - } else { - failAction.accept(pending); } + + failAction.accept(pending); } - + return false; } diff --git a/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java b/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java index a695f2f..a535697 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java +++ b/base/src/main/java/bjc/utils/ioutils/format/CLModifiers.java @@ -1,18 +1,45 @@ package bjc.utils.ioutils.format;
+/**
+ * A collection of the modifiers attached to a CL format directive.
+ *
+ * @author EVE
+ *
+ */
public class CLModifiers {
- public final boolean atMod;
- public final boolean colonMod;
+ /**
+ * Whether the at mod is on.
+ */
+ public final boolean atMod;
+ /**
+ * Whether the colon mod is on.
+ */
+ public final boolean colonMod;
+ /**
+ * Create a new set of CL modifiers.
+ *
+ * @param at
+ * The state of the at mod.
+ * @param colon
+ * The state of the colon mod.
+ */
public CLModifiers(boolean at, boolean colon) {
atMod = at;
colonMod = colon;
}
+ /**
+ * Create a set of modifiers from a modifier string.
+ *
+ * @param modString
+ * The string to parse modifiers from.
+ * @return A set of modifiers matching the string.
+ */
public static CLModifiers fromString(String modString) {
boolean atMod = false;
boolean colonMod = false;
- if (modString != null) {
+ if(modString != null) {
atMod = modString.contains("@");
colonMod = modString.contains(":");
}
diff --git a/base/src/main/java/bjc/utils/ioutils/format/Directive.java b/base/src/main/java/bjc/utils/ioutils/format/Directive.java index 0b1e889..fb03bbc 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/Directive.java +++ b/base/src/main/java/bjc/utils/ioutils/format/Directive.java @@ -4,11 +4,32 @@ import java.util.regex.Matcher; import bjc.utils.esodata.Tape; +/** + * A CL format directive. + * + * @author EVE + * + */ @FunctionalInterface public interface Directive { - /* - * @TODO fill in parameters + /** + * Execute this format directive. + * + * @param sb + * The buffer the string is being output to. + * @param item + * The current parameter being passed + * @param mods + * The directive modifiers + * @param arrParams + * The prefix parameters to the directive + * @param tParams + * All of the provided format parameters + * @param dirMatcher + * The matcher for format directives + * @param fmt + * The formatter itself. */ - public void format(StringBuffer sb, Object item, CLModifiers mods, - CLParameters arrParams, Tape<Object> tParams, Matcher dirMatcher, CLFormatter fmt); + public void format(StringBuffer sb, Object item, CLModifiers mods, CLParameters arrParams, Tape<Object> tParams, + Matcher dirMatcher, CLFormatter fmt); }
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/ioutils/format/EscapeException.java b/base/src/main/java/bjc/utils/ioutils/format/EscapeException.java index a1df55a..086f1cd 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/EscapeException.java +++ b/base/src/main/java/bjc/utils/ioutils/format/EscapeException.java @@ -1,14 +1,32 @@ package bjc.utils.ioutils.format;
+/**
+ * An exception thrown to escape CL iteration directives.
+ *
+ * @author EVE
+ *
+ */
public class EscapeException extends RuntimeException {
private static final long serialVersionUID = -4552821131068559005L;
+ /**
+ * Whether or not this exception should end iteration.
+ */
public final boolean endIteration;
+ /**
+ * Create a new escape exception.
+ */
public EscapeException() {
endIteration = false;
}
+ /**
+ * Create a new escape exception.
+ *
+ * @param end
+ * Whether or not to end the iteration.
+ */
public EscapeException(boolean end) {
endIteration = end;
}
diff --git a/base/src/main/java/bjc/utils/ioutils/format/IterationDirective.java b/base/src/main/java/bjc/utils/ioutils/format/IterationDirective.java index 353ff94..e13cb1c 100644 --- a/base/src/main/java/bjc/utils/ioutils/format/IterationDirective.java +++ b/base/src/main/java/bjc/utils/ioutils/format/IterationDirective.java @@ -2,9 +2,7 @@ package bjc.utils.ioutils.format; import bjc.utils.esodata.Tape; -import java.util.ArrayList; import java.util.IllegalFormatConversionException; -import java.util.List; import java.util.regex.Matcher; class IterationDirective implements Directive { |
