The StringListOps class contains some commonly used auxiliary class methods
that manipulate string lists.
All of these can easily be written in terms of the class methods from
the StringList contract; they are provided here for convenience.
Also for convenience, the StringListOps class also supplies all
of the StringList class methods.
By default, a StringListOps class method is invoked via
StringListOps.methodName(args), but this can
be abbreviated to SL.methodName(args)
by including the following "magical" declaration in the body
of a class:
public static StringListOps SL; // declare but never initialize this variable.
Because StringListOps includes both core StringList
methods and auxiliary methods, the above declaration enables
using the prefix SL. to access all of these class methods.
Class Methods
For convenience, the
public static StringList append (StringList L1, StringList L2)
Returns a string list whose length is the sum of the lengths ofL1andL2and whose elements are all the elements ofL1, in order, followed by all the elements ofL2, in order.
public static boolean equals (StringList L1, StringList L2)
ReturnstrueifL1andL2have the same length and the same elements in the same order (sameness of elements is determined by theequalsinstance method of theStringclass); otherwise returnsfalse. Note that theequalsmethod behaves differently than==on lists, which determines if two list nodes were created by the same call toprepend. For instance, ifLis the list[the,dog,barks], thenL.equals(prepend("the",tail(L)))istrue, butL == prepend("the",tail(L))isfalse.
public static boolean isMember (String s, StringList L)
Returnstrueifsis an element of the listLandfalseotherwise. Equality of strings is determined by theequalsinstance method of theStringclass.
public static int length (StringList L)
Returns the length ofL-- i.e., the number of non-empty list nodes inL.
public static StringList postpend (IntList L, String s)
Returns a list whose length is one more than the length ofLand whose elements are all the elements ofL, in order, followed byn.
public static StringList reverse (StringList L)
Returns a list whose length is the same as that asLand whose elements are all the elements ofLin reverse order.
StringListOps class also provides all the
class methods of the StringList class:
public static StringList empty() public static StringList prepend (String s, IntList L) public static boolean isEmpty (StringList L) public static String head (StringList L) public static StringList tail (StringList L) public static String toString (StringList L) public static StringList fromString (String s)