1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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;
/** 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.
* @param contents The contents of this block.
* @param startLine The line this block started on.
* @param endLine The line this block ended. */
public Block(
final int blockNo, final String contents, final int startLine,
final int endLine)
{
this.contents = contents;
this.startLine = startLine;
this.endLine = endLine;
this.blockNo = blockNo;
}
@Override
public String toString() {
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, endLine,
contents.length());
}
String fmt = "Block #%d (from lines %d to %d), length: %d characters";
return String.format(fmt, blockNo, startLine, endLine, contents.length());
}
}
|