package de.dhbwstuttgart.syntaxtree;

import org.antlr.v4.runtime.Token;

import com.google.common.collect.Lists;

import de.dhbwstuttgart.parser.NullToken;

import java.util.*;


/**
 * Stellt eine Deklarations-Liste von Generischen Variablen dar.
 * Kann vor Methoden und Klassen auftauchen. (<....>)
 * @author janulrich
 * 
 */
public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<GenericTypeVar>{

	private Token offsetOfLastElement;
	private List<GenericTypeVar> gtvs = new ArrayList<>();

	@SuppressWarnings("unchecked")
	public GenericDeclarationList(Iterable<? extends GenericTypeVar> values, Token endOffset) {
		super(endOffset);
		gtvs = isListOfGenericTypeVar(values) ? (List<GenericTypeVar>)values : Lists.newArrayList(values);
		this.offsetOfLastElement = endOffset;
	}

	public GenericDeclarationList(ArrayList<GenericTypeVar> values, Token endOffset) {
		super(endOffset);
		gtvs = values;
		this.offsetOfLastElement = endOffset;	}

	private boolean isListOfGenericTypeVar(Iterable<? extends GenericTypeVar> values) {
		return values instanceof List && ((List<?>)values).size() > 0 && ((List<?>)values).get(0) instanceof GenericTypeVar;
	}

	@Override
	public Iterator<GenericTypeVar> iterator() {
		return gtvs.iterator();
	}

	@Override
	public void accept(ASTVisitor visitor) {
		visitor.visit(this);
	}
	
	public String toString() {
		return this.gtvs.toString();
	}
}
