/** * Determine if the next few tokens match the expected values. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard. * </p> * * @param nextTokens the expected value of the next tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String[] nextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); Token token = null; for (String nextExpected : nextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false; } return true; }
@Test public void shouldReturnTrueFromHasNextIfThereIsACurrentToken() { content = "word"; makeCaseSensitive(); assertThat(tokens.currentToken().matches("word"), is(true)); assertThat(tokens.hasNext(), is(true)); }
/** * Determine if the next token matches one of the supplied values. * * @param firstOption the first option for the value of the current token * @param additionalOptions the additional 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 firstOption, String... additionalOptions ) throws IllegalStateException { if (completed) return false; Token current = currentToken(); if (current.matches(firstOption)) return true; for (String nextOption : additionalOptions) { if (current.matches(nextOption)) return true; } return false; }
/** * Determine if the next token matches one of the supplied values. * * @param firstOption the first option for the value of the current token * @param additionalOptions the additional 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 firstOption, String... additionalOptions ) throws IllegalStateException { if (completed) return false; Token current = currentToken(); if (current.matches(firstOption)) return true; for (String nextOption : additionalOptions) { if (current.matches(nextOption)) return true; } return false; }
/** * Determine if the next token matches one of the supplied values. * * @param firstOption the first option for the value of the current token * @param additionalOptions the additional 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 firstOption, String... additionalOptions ) throws IllegalStateException { if (completed) return false; Token current = currentToken(); if (current.matches(firstOption)) return true; for (String nextOption : additionalOptions) { if (current.matches(nextOption)) return true; } return false; }
/** * 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( Iterable<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 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( Iterable<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 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 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 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( Iterable<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 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 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)); }
/** * 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 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 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 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 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); }