All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 tokenClass) {
		
		return tokenClass.isAssignableFrom(get(index).getClass());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy