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

com.kero.security.lang.collections.TokenSequence Maven / Gradle / Ivy

Go to download

Kero-Security is a library for statically controlling access to properties of objects / classes.

There is a newer version: 0.1.39
Show newest version
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