org.watertemplate.interpreter.parser.Token Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of watertemplate-engine Show documentation
Show all versions of watertemplate-engine Show documentation
Lighweight, fast Java 8 template engine.
package org.watertemplate.interpreter.parser;
import java.util.Collections;
import java.util.List;
public class Token {
static final Token END_OF_INPUT = new Token("\0", Terminal.END_OF_INPUT);
private final String value;
private final List possibleTerminals;
Token(final String value, final Terminal possibleTerminals) {
this.possibleTerminals = Collections.singletonList(possibleTerminals);
this.value = value;
}
Token(final String value, final List possibleTerminals) {
this.possibleTerminals = possibleTerminals;
this.value = value;
}
String getValue() {
return value;
}
boolean canBe(final Terminal terminal) {
return possibleTerminals.contains(terminal);
}
@Override
public String toString() {
return "[" + possibleTerminals.stream().map(Enum::toString).reduce((a, b) -> a + "|" + b).get() + "] -> [" + value + "]";
}
}