Changeset 12362 in josm for trunk/src/org
- Timestamp:
- 2017-06-09T19:47:19+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java
r11393 r12362 14 14 import org.openstreetmap.josm.tools.JosmRuntimeException; 15 15 16 /** 17 * This class is used to parse a search string and split it into tokens. 18 * It provides methods to parse numbers and extract strings. 19 */ 16 20 public class PushbackTokenizer { 17 21 22 /** 23 * A range of long numbers. Immutable 24 */ 18 25 public static class Range { 19 26 private final long start; 20 27 private final long end; 21 28 29 /** 30 * Create a new range 31 * @param start The start 32 * @param end The end (inclusive) 33 */ 22 34 public Range(long start, long end) { 23 35 this.start = start; … … 25 37 } 26 38 39 /** 40 * @return The start 41 */ 27 42 public long getStart() { 28 43 return start; 29 44 } 30 45 46 /** 47 * @return The end (inclusive) 48 */ 31 49 public long getEnd() { 32 50 return end; … … 48 66 private boolean isRange; 49 67 68 /** 69 * Creates a new {@link PushbackTokenizer} 70 * @param search The search string reader to read the tokens from 71 */ 50 72 public PushbackTokenizer(Reader search) { 51 73 this.search = search; … … 53 75 } 54 76 77 /** 78 * The token types that may be read 79 */ 55 80 public enum Token { 81 /** 82 * Not token (-) 83 */ 56 84 NOT(marktr("<not>")), 85 /** 86 * Or token (or) (|) 87 */ 57 88 OR(marktr("<or>")), 89 /** 90 * Xor token (xor) (^) 91 */ 58 92 XOR(marktr("<xor>")), 93 /** 94 * opening parentheses token ( 95 */ 59 96 LEFT_PARENT(marktr("<left parent>")), 97 /** 98 * closing parentheses token ) 99 */ 60 100 RIGHT_PARENT(marktr("<right parent>")), 101 /** 102 * Colon : 103 */ 61 104 COLON(marktr("<colon>")), 105 /** 106 * The equals sign (=) 107 */ 62 108 EQUALS(marktr("<equals>")), 109 /** 110 * A text 111 */ 63 112 KEY(marktr("<key>")), 113 /** 114 * A question mark (?) 115 */ 64 116 QUESTION_MARK(marktr("<question mark>")), 117 /** 118 * Marks the end of the input 119 */ 65 120 EOF(marktr("<end-of-file>")), 121 /** 122 * Less than sign (<) 123 */ 66 124 LESS_THAN("<less-than>"), 125 /** 126 * Greater than sign (>) 127 */ 67 128 GREATER_THAN("<greater-than>"); 68 129 … … 210 271 } 211 272 273 /** 274 * Reads the next token if it is equal to the given, suggested token 275 * @param token The token the next one should be equal to 276 * @return <code>true</code> if it has been read 277 */ 212 278 public boolean readIfEqual(Token token) { 213 279 Token nextTok = nextToken(); … … 218 284 } 219 285 286 /** 287 * Reads the next token. If it is a text, return that text. If not, advance 288 * @return the text or <code>null</code> if the reader was advanced 289 */ 220 290 public String readTextOrNumber() { 221 291 Token nextTok = nextToken(); … … 226 296 } 227 297 298 /** 299 * Reads a number 300 * @param errorMessage The error if the number cannot be read 301 * @return The number that was found 302 * @throws ParseError if there is no number 303 */ 228 304 public long readNumber(String errorMessage) throws ParseError { 229 305 if ((nextToken() == Token.KEY) && (currentNumber != null)) … … 233 309 } 234 310 311 /** 312 * Gets the last number that was read 313 * @return The last number 314 */ 235 315 public long getReadNumber() { 236 316 return (currentNumber != null) ? currentNumber : 0; 237 317 } 238 318 319 /** 320 * Reads a range of numbers 321 * @param errorMessage The error if the input is malformed 322 * @return The range that was found 323 * @throws ParseError If the input is not as expected for a range 324 */ 239 325 public Range readRange(String errorMessage) throws ParseError { 240 326 if (nextToken() != Token.KEY || (currentNumber == null && currentRange == null)) { … … 255 341 } 256 342 343 /** 344 * Gets the last text that was found 345 * @return The text 346 */ 257 347 public String getText() { 258 348 return currentText;
Note:
See TracChangeset
for help on using the changeset viewer.