|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MementoTextInput.java | - | 78,6% | 75% | 76,9% |
|
1 | /* $Id: MementoTextInput.java,v 1.1 2006/10/20 20:23:05 m31 Exp $ | |
2 | * | |
3 | * This file is part of the project "Hilbert II" - http://www.qedeq.org | |
4 | * | |
5 | * Copyright 2000-2006, Michael Meyling <mime@qedeq.org>. | |
6 | * | |
7 | * "Hilbert II" is free software; you can redistribute | |
8 | * it and/or modify it under the terms of the GNU General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | */ | |
17 | ||
18 | package org.qedeq.kernel.parser; | |
19 | ||
20 | import java.util.Stack; | |
21 | ||
22 | import org.qedeq.kernel.utility.TextInput; | |
23 | ||
24 | /** | |
25 | * Remember TextInput positions. | |
26 | * | |
27 | * @version $Revision: 1.1 $ | |
28 | * @author Michael Meyling | |
29 | */ | |
30 | public final class MementoTextInput { | |
31 | ||
32 | /** For remembering input positions. */ | |
33 | private final Stack stack = new Stack(); | |
34 | ||
35 | /** Input source to parse. */ | |
36 | private final TextInput input; | |
37 | ||
38 | /** | |
39 | * Constructor. | |
40 | * | |
41 | * @param input Input source to parse. | |
42 | */ | |
43 | 81 | public MementoTextInput(final TextInput input) { |
44 | 81 | this.input = input; |
45 | } | |
46 | ||
47 | /** | |
48 | * Remember current position. | |
49 | */ | |
50 | 12966 | public void markPosition() { |
51 | 12966 | stack.push(new Integer(input.getPosition())); |
52 | } | |
53 | ||
54 | /** | |
55 | * Rewind to previous marked position. Also clears the mark. | |
56 | * | |
57 | * @return Current position before pop. | |
58 | */ | |
59 | 7378 | public long rewindPosition() { |
60 | 7378 | final long oldPosition = getPosition(); |
61 | 7378 | input.setPosition(((Integer) stack.pop()).intValue()); |
62 | 7378 | return oldPosition; |
63 | } | |
64 | ||
65 | /** | |
66 | * Forget last remembered position. | |
67 | */ | |
68 | 5588 | public void clearMark() { |
69 | 5588 | stack.pop(); |
70 | } | |
71 | ||
72 | /** | |
73 | * Get byte position. | |
74 | * | |
75 | * @return Position. | |
76 | */ | |
77 | 7378 | public long getPosition() { |
78 | 7378 | return input.getPosition(); |
79 | } | |
80 | ||
81 | /** | |
82 | * Reads a single character and does not change the reading | |
83 | * position. | |
84 | * | |
85 | * @return character read, if there are no more chars | |
86 | * <code>Character.MAX_VALUE</code> is returned | |
87 | */ | |
88 | 50909 | public int getChar() { |
89 | 50909 | return input.getChar(); |
90 | } | |
91 | ||
92 | /** | |
93 | * Reads a single character and increments the reading position | |
94 | * by one. | |
95 | * | |
96 | * @return character read, if there are no more chars | |
97 | * <code>Character.MAX_VALUE</code> is returned | |
98 | */ | |
99 | 11360 | public int readChar() { |
100 | 11360 | return input.read(); |
101 | } | |
102 | ||
103 | /** | |
104 | * Are there still any characters to read? | |
105 | * | |
106 | * @return Anything left for reading further? | |
107 | */ | |
108 | 17182 | public final boolean eof() { |
109 | 17182 | return input.isEmpty(); |
110 | } | |
111 | ||
112 | /** | |
113 | * Get rewind stack size. | |
114 | * | |
115 | * @return Rewind stack size. | |
116 | */ | |
117 | 79 | public int getRewindStackSize() { |
118 | 79 | return stack.size(); |
119 | } | |
120 | ||
121 | /** | |
122 | * Returns the current column number. | |
123 | * | |
124 | * @return Current column number (starting with line 1). | |
125 | */ | |
126 | 0 | public int getColumn() { |
127 | 0 | return input.getColumn(); |
128 | } | |
129 | ||
130 | /** | |
131 | * Returns the current line number. | |
132 | * | |
133 | * @return Current line number (starting with line 1). | |
134 | */ | |
135 | 0 | public int getRow() { |
136 | 0 | return input.getRow(); |
137 | } | |
138 | ||
139 | /** | |
140 | * Returns the current line. | |
141 | * | |
142 | * @return Current line. | |
143 | */ | |
144 | 0 | public String getLine() { |
145 | 0 | return input.getLine(); |
146 | } | |
147 | ||
148 | } |
|