package dk.itu.mario.level.grammar;

import java.util.ArrayList;
import java.util.List;

public class AndClause implements Clause {
	List<Clause> subClauses = new ArrayList<Clause>();
	
	public AndClause(List<Clause> subClauses) {
		this.subClauses.addAll(subClauses);
	}
	
	public AndClause(Clause... subClauses) {
		for (Clause clause : subClauses) {
			this.subClauses.add(clause);
		}
	}

	@Override
	public Clause makeRandomChoice() {
		throw new UnsupportedOperationException();
	}

	@Override
	public int getNumSubClauses() {
		return subClauses.size();
	}

	@Override
	public Clause getSubClause(int index) {
		// TODO Auto-generated method stub
		return subClauses.get(index);
	}

	@Override
	public boolean isChoice() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isTerminal() {
		return false;
	}
	@Override
	public boolean isVariable() {
		return false;
	}
	@Override
	public String toString() {
		if (subClauses.size() == 0) {
			return "(Empty AND clause)";
		}
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		for (int i = 0; i < subClauses.size() - 1; i ++) {
			sb.append(subClauses.get(i).toString());
			sb.append(" + ");
		}
		sb.append(subClauses.get(subClauses.size()-1).toString());
		sb.append(")");
		return sb.toString();
	}
}