package coll;

/* Immutable Collection
 * by Martin Robinson
 * \__________________/
 *       /
 * \ ('<
 * (<=)
 * */

/*
 * fibonacci sequence generator
 * simple example of generator.
 * generator are list with
 * computable sequence. this one
 * is the fibonacci sequence.
 * we dont need to store them all
 * when we can calculate it for
 * every index asked.
 * \__________________________/
 *       /
 * \ ('<
 * (<=>
 * */
/**
 * @author martin
 *fibonacci number sequence
 */
public final class Fibb extends Coll<Integer>{
	/**
	 *private constructor
	 */
	private Fibb(){}

	private static Lst<Integer> _singleton = new Fibb();
	/**
	 * return infinite fibonacci sequence
	 * @return singleton
	 */
	public static Lst<Integer> singleton(){
		return _singleton;
	}
	/**
	 * return limited fibbonacci sequence
	 * @param size of the sequence
	 * @return singleton.limit()
	 */
	public static Lst<Integer> fromSize(int size){
		return _singleton.limit(size);
	}
	/* (non-Javadoc)
	 * @see coll.Lst#get(int)
	 */
	public Integer get(int i) {
		if (i<0)
			throw new ArrayIndexOutOfBoundsException();
		if (i==0 || i==1)
			return 1;
		return get(i-1) + get(i-2);
	}
	/* (non-Javadoc)
	 * @see coll.Lst#size()
	 */
	public int size() {
		return 0;
	}
	/* (non-Javadoc)
	 * @see coll.Lst#undo()
	 */
	public Lst<Integer> undo() {
		return null;
	}
}
