From a24c1042499f76ff2d442ae133ef165011a7af4c Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 12 Jul 2021 15:53:22 -0300 Subject: Formatting tweaks --- .../utils/ioutils/blocks/SimpleBlockReader.java | 77 ++++++++-------------- 1 file changed, 28 insertions(+), 49 deletions(-) (limited to 'base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java') diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java index 94405c9..3eb57d0 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java @@ -1,49 +1,34 @@ package bjc.utils.ioutils.blocks; -import java.io.IOException; -import java.io.Reader; -import java.util.NoSuchElementException; -import java.util.Scanner; -import java.util.regex.Pattern; +import java.io.*; +import java.util.*; +import java.util.regex.*; -import bjc.utils.funcutils.StringUtils; +import bjc.utils.funcutils.*; -/** - * Simple implementation of {@link BlockReader}. +/** Simple implementation of {@link BlockReader}. * * NOTE: The EOF marker is always treated as a delimiter. You are expected to * handle blocks that may be shorter than you expect. * - * @author EVE - * - */ + * @author EVE */ public class SimpleBlockReader implements BlockReader { - /* - * I/O source for blocks. - */ + /* I/O source for blocks. */ private final Scanner blockReader; - /* - * The current block. - */ + /* The current block. */ private Block currBlock; - /* - * Info about the current block. - */ + /* Info about the current block. */ private int blockNo; private int lineNo; - /** - * Create a new block reader. + /** Create a new block reader. * - * @param blockDelim - * The pattern that separates blocks. Note that the end of + * @param blockDelim The pattern that separates blocks. Note that the end of * file is always considered to end a block. * - * @param source - * The source to read blocks from. - */ + * @param source The source to read blocks from. */ public SimpleBlockReader(final String blockDelim, final Reader source) { blockReader = new Scanner(source); @@ -55,17 +40,13 @@ public class SimpleBlockReader implements BlockReader { lineNo = 1; } - /** - * Create a new block reader. + /** Create a new block reader. * - * @param blockDelim - * The pattern that separates blocks. Note that the end of + * @param blockDelim The pattern that separates blocks. Note that the end of * file is always considered to end a block. * - * @param source - * The source to read blocks from. NOTE: This does modify the - * provided scanner. - */ + * @param source The source to read blocks from. NOTE: This does modify the + * provided scanner. */ public SimpleBlockReader(final String blockDelim, final Scanner source) { blockReader = source; @@ -90,19 +71,19 @@ public class SimpleBlockReader implements BlockReader { @Override public boolean nextBlock() { try { - /* - * Read in a new block, and keep the line numbers sane. - */ + /* Read in a new block, and keep the line numbers sane. */ final String blockContents = blockReader.next(); + final int numLines = StringUtils.countMatches(blockContents, "\\R"); + final int blockStartLine = lineNo; - final int blockEndLine - = lineNo + StringUtils.countMatches(blockContents, "\\R"); + final int blockEndLine = lineNo + numLines; - lineNo = blockEndLine; + lineNo = blockEndLine; blockNo += 1; - currBlock = new Block(blockNo, blockContents, blockStartLine, blockEndLine); + currBlock = new Block( + blockNo, blockContents, blockStartLine, blockEndLine); return true; } catch (final NoSuchElementException nseex) { @@ -124,19 +105,17 @@ public class SimpleBlockReader implements BlockReader { blockReader.close(); } - /** - * Set the delimiter used to separate blocks. + /** Set the delimiter used to separate blocks. * - * @param delim - * The delimiter used to separate blocks. - */ + * @param delim The delimiter used to separate blocks. */ public void setDelimiter(final String delim) { blockReader.useDelimiter(delim); } @Override public String toString() { - return String.format("SimpleBlockReader [currBlock=%s, blockNo=%s]", currBlock, - blockNo); + return String.format( + "SimpleBlockReader [currBlock=%s, blockNo=%s]", + currBlock, blockNo); } } -- cgit v1.2.3