sclass MinimalChain implements Iterable { A element; MinimalChain next; *() {} *(A *element) {} *(A *element, MinimalChain *next) {} toString { ret str(toList()); } ArrayList toList() { new ArrayList l; MinimalChain c = this; while (c != null) { l.add(c.element); c = c.next; } ret l; } void setElement(A a) { element = a; } void setNext(MinimalChain next) { this.next = next; } // TODO: optimize public Iterator iterator() { ret toList().iterator(); } A get() { ret element; } }