/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }
/** * Determine if the current token matches the expected token type. * * @param expectedType the expected token type of the current token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int expectedType ) throws IllegalStateException { return !completed && currentToken().matches(expectedType); }
/** * Determine if the current token matches the expected value. * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( char expected ) throws IllegalStateException { return !completed && currentToken().matches(expected); }
/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }
/** * Determine if the current token matches the expected token type. * * @param expectedType the expected token type of the current token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int expectedType ) throws IllegalStateException { return !completed && currentToken().matches(expectedType); }
/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }
/** * Determine if the current token matches the expected token type. * * @param expectedType the expected token type of the current token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int expectedType ) throws IllegalStateException { return !completed && currentToken().matches(expectedType); }
/** * Determine if the current token matches the expected value. * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( char expected ) throws IllegalStateException { return !completed && currentToken().matches(expected); }
/** * Determine if the current token matches the expected value. * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( char expected ) throws IllegalStateException { return !completed && currentToken().matches(expected); }
/** * Determine if the current token matches the expected value. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String expected ) throws IllegalStateException { return !completed && (expected == ANY_VALUE || currentToken().matches(expected)); }
@Override public final boolean matches( int expectedType ) { return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType; }
@Override public final boolean matches( int expectedType ) { return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType; }
/** * Determine if the current token matches the expected value. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String expected ) throws IllegalStateException { return !completed && (expected == ANY_VALUE || currentToken().matches(expected)); }
@Override public final boolean matches( int expectedType ) { return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType; }
/** * Determine if the current token matches the expected value. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match, or false if the current token did not match * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String expected ) throws IllegalStateException { return !completed && (expected == ANY_VALUE || currentToken().matches(expected)); }
/** * Determine if the next token matches one of the supplied values. * * @param options the options for the value of the current token * @return true if the current token's value did match one of the suplied options, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matchesAnyOf( String[] options ) throws IllegalStateException { if (completed) return false; Token current = currentToken(); for (String option : options) { if (current.matches(option)) return true; } return false; }
/** * Determine if the next token have one of the supplied types. * * @param typeOptions the options for the type of the current token * @return true if the current token's type matched one of the supplied options, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matchesAnyOf( int[] typeOptions ) throws IllegalStateException { if (completed) return false; int currentType = currentToken().type(); for (int nextTypeOption : typeOptions) { if (currentType == nextTypeOption) return true; } return false; }
/** * Return the value of this token and move to the next token. * * @return the value of the current token * @throws ParsingException if there is no such token to consume * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consume() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String result = currentToken().value(); moveToNextToken(); return result; }
/** * Return the value of this token and move to the next token. * * @return the value of the current token * @throws ParsingException if there is no such token to consume * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consume() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String result = currentToken().value(); moveToNextToken(); return result; }
@Test public void shouldReturnTrueFromHasNextIfThereIsACurrentToken() { content = "word"; makeCaseSensitive(); assertThat(tokens.currentToken().matches("word"), is(true)); assertThat(tokens.hasNext(), is(true)); }