Ignore:
Timestamp:
2017-06-09T19:47:19+02:00 (7 years ago)
Author:
michael2402
Message:

Javadoc: PushbackTokenizer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java

    r11393 r12362  
    1414import org.openstreetmap.josm.tools.JosmRuntimeException;
    1515
     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 */
    1620public class PushbackTokenizer {
    1721
     22    /**
     23     * A range of long numbers. Immutable
     24     */
    1825    public static class Range {
    1926        private final long start;
    2027        private final long end;
    2128
     29        /**
     30         * Create a new range
     31         * @param start The start
     32         * @param end The end (inclusive)
     33         */
    2234        public Range(long start, long end) {
    2335            this.start = start;
     
    2537        }
    2638
     39        /**
     40         * @return The start
     41         */
    2742        public long getStart() {
    2843            return start;
    2944        }
    3045
     46        /**
     47         * @return The end (inclusive)
     48         */
    3149        public long getEnd() {
    3250            return end;
     
    4866    private boolean isRange;
    4967
     68    /**
     69     * Creates a new {@link PushbackTokenizer}
     70     * @param search The search string reader to read the tokens from
     71     */
    5072    public PushbackTokenizer(Reader search) {
    5173        this.search = search;
     
    5375    }
    5476
     77    /**
     78     * The token types that may be read
     79     */
    5580    public enum Token {
     81        /**
     82         * Not token (-)
     83         */
    5684        NOT(marktr("<not>")),
     85        /**
     86         * Or token (or) (|)
     87         */
    5788        OR(marktr("<or>")),
     89        /**
     90         * Xor token (xor) (^)
     91         */
    5892        XOR(marktr("<xor>")),
     93        /**
     94         * opening parentheses token (
     95         */
    5996        LEFT_PARENT(marktr("<left parent>")),
     97        /**
     98         * closing parentheses token )
     99         */
    60100        RIGHT_PARENT(marktr("<right parent>")),
     101        /**
     102         * Colon :
     103         */
    61104        COLON(marktr("<colon>")),
     105        /**
     106         * The equals sign (=)
     107         */
    62108        EQUALS(marktr("<equals>")),
     109        /**
     110         * A text
     111         */
    63112        KEY(marktr("<key>")),
     113        /**
     114         * A question mark (?)
     115         */
    64116        QUESTION_MARK(marktr("<question mark>")),
     117        /**
     118         * Marks the end of the input
     119         */
    65120        EOF(marktr("<end-of-file>")),
     121        /**
     122         * Less than sign (<)
     123         */
    66124        LESS_THAN("<less-than>"),
     125        /**
     126         * Greater than sign (>)
     127         */
    67128        GREATER_THAN("<greater-than>");
    68129
     
    210271    }
    211272
     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     */
    212278    public boolean readIfEqual(Token token) {
    213279        Token nextTok = nextToken();
     
    218284    }
    219285
     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     */
    220290    public String readTextOrNumber() {
    221291        Token nextTok = nextToken();
     
    226296    }
    227297
     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     */
    228304    public long readNumber(String errorMessage) throws ParseError {
    229305        if ((nextToken() == Token.KEY) && (currentNumber != null))
     
    233309    }
    234310
     311    /**
     312     * Gets the last number that was read
     313     * @return The last number
     314     */
    235315    public long getReadNumber() {
    236316        return (currentNumber != null) ? currentNumber : 0;
    237317    }
    238318
     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     */
    239325    public Range readRange(String errorMessage) throws ParseError {
    240326        if (nextToken() != Token.KEY || (currentNumber == null && currentRange == null)) {
     
    255341    }
    256342
     343    /**
     344     * Gets the last text that was found
     345     * @return The text
     346     */
    257347    public String getText() {
    258348        return currentText;
Note: See TracChangeset for help on using the changeset viewer.