/** * Interface to a sequential list of strings. * Demonstration program for CSE 143. * @author Hal Perkins * @version 0.1, 4/17/06 */ public interface StringList { // query functions /** * Return the size of this list * @return number of items currently in the list */ public int size(); /** * Report whether this list is empty or not * @return true if the list is empty, otherwise false */ public boolean isEmpty(); /** * Return the location of a string in this list * @param s the string to be located * @return the index of s in the list if it is present, otherwise -1 */ public int indexOf(String s); /** * Report whether this list contains a particular string * @param s string to search for * @return true if s is contained in the list, false otherwise */ public boolean contains(String s); /** * Return the list element at a given position in this list * @param pos position of desired element (must be 0 <= pos < size) * @return the list element at that position */ public String get(int pos); // list modifications /** * Change the item at a given position to a new value * @param pos position in the list to be changed (must be 0 <= pos < size) * @param s new value to put at that position */ public void set(int pos, String s); /** * Add a new item to the end of this StringList. * pre: list is not full * @param s the string to add to the list */ public void add(String s); /** * Add a new item to this list at a specified position * @param pos location where string should be added * (pre: 0 <= pos < size, and list is not full) * @param s string to be added */ public void add(int pos, String s); /** * Remove the item at the specified position from this list * @param pos position of the item to be removed (must be 0 <= pos < size) */ public void remove(int pos); // toString /** * Return a string representation of this StringList * @return A list of the items in this list separated by commas * and surrounded by brackets */ public String toString(); }