import tester.ISame; /** * This class represents an nonempty list of items of the type * T. * * @param the data type of the items in this list */ class ConsLo> implements ILo{ /** the first item in this list */ T first; /** the rest of this list */ ILo rest; /** * The full constructor * @param first the first item in this list * @param rest the rest of this list */ ConsLo(T first, ILo rest){ this.first = first; this.rest = rest; } /* TEMPLATE: FIELDS: ... this.first ... -- T ... this.rest ... -- ILo METHODS FOR FIELDS: ... this.first.same(T) ... -- boolean ... this.rest.size() ... -- int ... this.rest.contains(T) ... -- boolean */ /** * Compute the total size of this list. * @return the size of this list */ public int size(){ return 1 + this.rest.size(); } /** * Does this list of accounts contain the given account? * @param a the given account * @return true if the accounts are the same */ public boolean contains(T t){ return ((ISame)this.first).same(t) || this.rest.contains(t); } }