From 327c2a35bde7a13d77f343464e41e19e4a214790 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sat, 13 Oct 2018 15:51:53 -0400 Subject: General cleanup and documentation. Cleanup files, and add missing comments in places. --- .../main/java/bjc/utils/ioutils/blocks/Block.java | 61 ++++++---------------- 1 file changed, 17 insertions(+), 44 deletions(-) (limited to 'base/src/main/java/bjc/utils/ioutils/blocks') diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/Block.java b/base/src/main/java/bjc/utils/ioutils/blocks/Block.java index 61d473c..bf0257e 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/Block.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/Block.java @@ -27,19 +27,26 @@ public class Block { */ public final int blockNo; + /** + * The line offset number for this block. + * + * Essentially, this is the absolute number of lines that this block is + * into whatever source it came from, where as startLine and endLine are + * relative to the BlockReader this Block is from. + */ public int lineOffset; /** * Create a new block. * * @param blockNo - * The number of this block. + * The number of this block. * @param contents - * The contents of this block. + * The contents of this block. * @param startLine - * The line this block started on. + * The line this block started on. * @param endLine - * The line this block ended. + * The line this block ended. */ public Block(final int blockNo, final String contents, final int startLine, final int endLine) { this.contents = contents; @@ -48,51 +55,17 @@ public class Block { this.blockNo = blockNo; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - - result = prime * result + blockNo; - result = prime * result + (contents == null ? 0 : contents.hashCode()); - result = prime * result + endLine; - result = prime * result + startLine; - - return result; - } - - @Override - public boolean equals(final Object obj) { - if(this == obj) return true; - if(obj == null) return false; - if(!(obj instanceof Block)) return false; - - final Block other = (Block) obj; - - if(blockNo != other.blockNo) return false; - - if(contents == null) { - if(other.contents != null) return false; - } else if(!contents.equals(other.contents)) return false; - - if(endLine != other.endLine) return false; - if(startLine != other.startLine) return false; - - return true; - } - @Override public String toString() { - if(lineOffset != -1) { + if (lineOffset != -1) { String fmt = "Block #%d (from lines %d (%d) to %d (%d)), length: %d characters"; - return String.format(fmt, blockNo, startLine + lineOffset, - startLine, endLine + lineOffset, + return String.format(fmt, blockNo, startLine + lineOffset, startLine, endLine + lineOffset, endLine + lineOffset, contents.length()); - } else { - String fmt = "Block #%d (from lines %d to %d), length: %d characters"; - - return String.format(fmt, blockNo, startLine, endLine, contents.length()); } + + String fmt = "Block #%d (from lines %d to %d), length: %d characters"; + + return String.format(fmt, blockNo, startLine, endLine, contents.length()); } } -- cgit v1.2.3 From d5915c773f9e8c65126f2fd2ea03a6b47f2aa9b7 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 14 Oct 2018 11:46:19 -0400 Subject: Cleanup --- base/src/main/java/bjc/utils/ioutils/blocks/SerialBlockReader.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'base/src/main/java/bjc/utils/ioutils/blocks') diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/SerialBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/SerialBlockReader.java index 02483c1..66ebd66 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/SerialBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/SerialBlockReader.java @@ -2,6 +2,7 @@ package bjc.utils.ioutils.blocks; import java.io.IOException; import java.util.Deque; +import java.util.LinkedList; /** * Provides a means of concatenating two block readers. @@ -21,6 +22,8 @@ public class SerialBlockReader implements BlockReader { * The readers to pull from, in the order to pull from them. */ public SerialBlockReader(final BlockReader... readers) { + readerQueue = new LinkedList<>(); + for(final BlockReader reader : readers) { readerQueue.add(reader); } -- cgit v1.2.3