package org.seamframework.sql;

import java.util.List;
import java.util.NoSuchElementException;

public class Tuple {
	
	private final List<Expression<?>> selections;
	private final List<Object> elements;
	
	Tuple(List<Expression<?>> selections, List<Object> values) {
		this.selections = selections;
		this.elements = values;
	}

	@SuppressWarnings("unchecked")
	public <T> T get(Selection<T> selection) {
		int column = selections.indexOf(selection);
		return (T) get(column);
	}
	
	@SuppressWarnings("unchecked")
	public <T> T get(int column, Type<T> type) {
		return (T) get(column);
	}
	
	@SuppressWarnings("unchecked")
	public <T> T testGet(int column) {
		return (T) get(column);
	}
	
	public Object get(int column) {
		if (column>=elements.size() || column<0) {
			throw new NoSuchElementException();
		}
		return elements.get(column);
	}
	
	public List<Expression<?>> getSelections() {
		return selections;
	}
	
	public List<Object> getElements() {
		return elements;
	}

}
