CS111 IntListList Contract

The IntListList class describes immutable linked lists whose elements are integer lists. A list of integer lists is defined recursively as either

Lists of integer lists are immutable in the sense that the head or tail of a list node cannot be changed after the list node has been created (via the prepend() method).

There are no public constructor or instance methods for list of integer lists; they are created and manipulated by the class methods below. By default, an IntListList class method is invoked via IntListList.methodName(args), but this can be abbreviated to ILL.methodName(args) by including the following "magical" declaration in the body of a class:

public static IntListList ILL; // declare but never initialize this variable.

Class Methods

public static IntListList empty()
Returns an empty list of integer lists.

public static IntListList prepend (IntList x, IntListList L)
Returns a new list of integer lists node whose head is x and whose tail is L. Returns a new list of integer lists node whose head is x and whose tail is L. From another perspective, returns a list whose length is one more than the length of L and whose elements are x followed by the elements of L, in order.

public static boolean isEmpty (IntListList L)
Returns true if L is an empty list of integer lists and false if L is a list of integer lists node.

public static IntList head (IntListList L)
Returns the integer list that is the head component of the list of integer lists node L. Signals an exception if L is empty.

public static IntListList tail (IntListList L)
Returns the list of integer lists that is the tail component of the list of integer lists node L. Signals an exception if L is empty.

public static String toString (IntListList L)
Returns a string representation of the list of integer lists L in which the integer list elements are separated by commas and delimited by square brackets. For example, if L1 is a list containing the sequence of integer lists whose printed representations are [7,1,4], [6], and [-3,-8], then toString(L1) returns "[[7,1,4],[6],[-3,-8]]".

public static IntListList fromString (String s)
If s is the printed representation of a list of integer lists (i.e., comma separated integer list representations delimited by square brackets), returns an IntListList with that representation. For example, fromString("[[7,1,4],[6],[-3,-8]]") returns an 3-element list of integer lists whose elements are the integer lists [7,1,4], [6], and [-3,-8]. If s is not the printed representation of an integer list, signals an error.