|
1 |
| package com.agical.rdoc.core.model.impl; |
|
2 |
| |
|
3 |
| import java.util.HashMap; |
|
4 |
| import java.util.Map; |
|
5 |
| |
|
6 |
| import com.agical.rdoc.core.model.CodeBlock; |
|
7 |
| |
|
8 |
| public class CodeBlockImpl implements CodeBlock { |
|
9 |
| private class FromMarkCodeBlock implements CodeBlock { |
|
10 |
| private final CodeBlockImpl decoratedBlock; |
|
11 |
| private final int fromMark; |
|
12 |
| |
|
13 |
5
| public FromMarkCodeBlock(CodeBlockImpl decoratedBlock, int fromMark) {
|
|
14 |
5
| this.decoratedBlock = decoratedBlock;
|
|
15 |
5
| this.fromMark = fromMark;
|
|
16 |
| } |
|
17 |
| |
|
18 |
0
| public CodeBlock addCode(String data) {
|
|
19 |
0
| decoratedBlock.addCode(data);
|
|
20 |
0
| return this;
|
|
21 |
| } |
|
22 |
| |
|
23 |
0
| public CodeBlock addCode(char data) {
|
|
24 |
0
| decoratedBlock.addCode(data);
|
|
25 |
0
| return this;
|
|
26 |
| } |
|
27 |
| |
|
28 |
0
| public void mark(String id) {
|
|
29 |
0
| decoratedBlock.mark(id);
|
|
30 |
| } |
|
31 |
| |
|
32 |
2
| public String to(String mark) {
|
|
33 |
2
| Integer toMark = (Integer) decoratedBlock.markIndex.get(mark);
|
|
34 |
2
| return decoratedBlock.buffer.substring(fromMark, toMark.intValue());
|
|
35 |
| } |
|
36 |
| |
|
37 |
0
| public CodeBlock from(String mark) {
|
|
38 |
0
| return decoratedBlock.from(mark);
|
|
39 |
| } |
|
40 |
| |
|
41 |
3
| public String toString() {
|
|
42 |
3
| return decoratedBlock.buffer.substring(fromMark);
|
|
43 |
| } |
|
44 |
| } |
|
45 |
| |
|
46 |
| private StringBuffer buffer = new StringBuffer(); |
|
47 |
| Map markIndex = new HashMap(); |
|
48 |
| |
|
49 |
6728
| public CodeBlock addCode(String data) {
|
|
50 |
6728
| buffer.append(data);
|
|
51 |
6728
| return this;
|
|
52 |
| } |
|
53 |
| |
|
54 |
29
| public CodeBlock addCode(char data) {
|
|
55 |
29
| buffer.append(data);
|
|
56 |
29
| return this;
|
|
57 |
| } |
|
58 |
21
| public String toString() {
|
|
59 |
21
| return buffer.toString();
|
|
60 |
| } |
|
61 |
| |
|
62 |
77
| public void mark(String id) {
|
|
63 |
77
| markIndex.put(id, new Integer(buffer.length()));
|
|
64 |
| } |
|
65 |
| |
|
66 |
3
| public String to(String mark) {
|
|
67 |
3
| Integer toMark = (Integer) markIndex.get(mark);
|
|
68 |
3
| return buffer.substring(0, toMark.intValue());
|
|
69 |
| } |
|
70 |
| |
|
71 |
5
| public CodeBlock from(String mark) {
|
|
72 |
5
| return new FromMarkCodeBlock(this, ((Integer) markIndex.get(mark)).intValue());
|
|
73 |
| } |
|
74 |
| } |