com.kero.security.lang.collections.TokenSequence Maven / Gradle / Ivy
package com.kero.security.lang.collections;
import java.util.LinkedList;
import com.kero.security.lang.tokens.KsdlToken;
public class TokenSequence extends LinkedList {
private static final long serialVersionUID = 1L;
public TokenSequence() {
super();
}
public TokenSequence(TokenSequence seq) {
super(seq);
}
public T tryGetOrDefault(T def) {
return tryGetOrDefault((Class) def.getClass(), def);
}
public T tryGetOrDefault(Class tokenClass, T def) {
if(!isToken(0, tokenClass)) return def;
return (T) poll();
}
public boolean isToken(int index, KsdlToken token) {
if(index >= size()) return false;
return get(index) == token;
}
public boolean isToken(int index, Class extends KsdlToken> tokenClass) {
return tokenClass.isAssignableFrom(get(index).getClass());
}
}