com.kero.security.lang.collections.TokenSequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kero-security Show documentation
Show all versions of kero-security Show documentation
Kero-Security is a library for statically controlling access to properties of objects / classes.
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());
}
}