diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-04-06 14:14:37 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-04-06 14:14:37 -0400 |
| commit | 25382427eeafda30aa06a27f37c65fdaf8b67eba (patch) | |
| tree | 109a2c5c4cd74ce47b961710952a26520bc17f90 /BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java | |
| parent | 622653daa9e991e9608852210034a4e09cb94167 (diff) | |
Reorganize blocks
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java new file mode 100644 index 0000000..e92644e --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/Block.java @@ -0,0 +1,87 @@ +package bjc.utils.ioutils.blocks; + +/** + * Represents a block of text read in from a source. + * + * @author EVE + * + */ +public class Block { + /** + * The contents of this block. + */ + public final String contents; + + /** + * The line of the source this block started on. + */ + public final int startLine; + + /** + * The line of the source this block ended on. + */ + public final int endLine; + + /** + * The number of this block. + */ + public final int blockNo; + + /** + * Create a new block. + * + * @param blockNo + * The number of this block. + * @param contents + * The contents of this block. + * @param startLine + * The line this block started on. + * @param endLine + * The line this block ended. + */ + public Block(int blockNo, String contents, int startLine, int endLine) { + this.contents = contents; + this.startLine = startLine; + this.endLine = endLine; + 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(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof Block)) return false; + + 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() { + return String.format("Block #%d (from lines %d to %d), length: %d characters", blockNo, startLine, + endLine, contents.length()); + } +}
\ No newline at end of file |
