package coll;
/* Immutable Collection
 * by Martin Robinson
 * \__________________/
 *       /
 * \ ('<
 * (<=)
 * */
/*
 * empty list generator
 * this list is filled with
 * null. but it does not
 * make sense to store an
 * entire array of null, so
 * we dont, we simply return
 * null to every index unless
 * specified size is not met
 * \_______________________/
 *      /
 * \ ('<
 * (<=>
 * */
/**
 * @author martin
 *empty list, filled with null
 * @param <E>
 */
public final class EmptyLst<E> extends Coll<E>{
	private final int _size;

	/**
	 * private constructor
	 * @param size
	 */
	private EmptyLst(int size){
		_size = size;
	}

	/**
	 * static factory
	 * empty sized list
	 * @param size
	 * @return new EmptyList
	 */
	public static <E> Lst<E> fromSize(int size){
		if (size < 0)
			throw new IllegalArgumentException();
		if (size == 0)
			return _singleton;
		return new EmptyLst(size);
	}

	private static Lst _singleton = new EmptyLst(0);
	/**
	 * static factory
	 * return empty zero size list
	 * @return singleton
	 */
	public static <E> Lst<E> fromEmpty(){
		return _singleton;
	}

	/* (non-Javadoc)
	 * @see coll.Lst#get(int)
	 */
	public E get(int i) {
		if (i < 0 || i >= _size)
			throw new ArrayIndexOutOfBoundsException();
		return null;
	}

	/* (non-Javadoc)
	 * @see coll.Lst#size()
	 */
	public int size() {
		return _size;
	}

	/* (non-Javadoc)
	 * @see coll.Lst#undo()
	 */
	public Lst undo() {
		return null;
	}
}
