123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import java.util.Iterator;
  2. /**
  3. * Interface for a simple List. Random access to all items in the list is provided.
  4. * The numbering of elements in the list begins at 0.
  5. *
  6. */
  7. public interface IList<E> extends Iterable<E>{
  8. /**
  9. * Add an item to the end of this list.
  10. * <br>pre: none
  11. * <br>post: size() = old size() + 1, get(size() - 1) = item
  12. * @param item the data to be added to the end of this list
  13. */
  14. void add(E item);
  15. /**
  16. * Insert an item at a specified position in the list.
  17. * <br>pre: 0 <= pos <= size()
  18. * <br>post: size() = old size() + 1, get(pos) = item, all elements in
  19. * the list with a positon >= pos have a position = old position + 1
  20. * @param pos the position to insert the data at in the list
  21. * @param item the data to add to the list
  22. */
  23. void insert(int pos, E item);
  24. /**
  25. * Change the data at the specified position in the list.
  26. * the old data at that position is returned.
  27. * <br>pre: 0 <= pos < size()
  28. * <br>post: get(pos) = item, return the
  29. * old get(pos)
  30. * @param pos the position in the list to overwrite
  31. * @param item the new item that will overwrite the old item
  32. * @return the old data at the specified position
  33. */
  34. E set(int pos, E item);
  35. /**
  36. * Get an element from the list.
  37. * <br>pre: 0 <= pos < size()
  38. * <br>post: return the item at pos
  39. * @param pos specifies which element to get
  40. * @return the element at the specified position in the list
  41. */
  42. E get(int pos);
  43. /**
  44. * Remove an element in the list based on position.
  45. * <br>pre: 0 <= pos < size()
  46. * <br>post: size() = old size() - 1, all elements of
  47. * list with a positon > pos have a position = old position - 1
  48. * @param pos the position of the element to remove from the list
  49. * @return the data at position pos
  50. */
  51. E remove(int pos);
  52. /**
  53. * Remove the first occurrence of obj in this list.
  54. * Return <tt>true</tt> if this list changed as a result of this call, <tt>false</tt> otherwise.
  55. * <br>pre: none
  56. * <br>post: if obj is in this list the first occurence has been removed and size() = old size() - 1.
  57. * If obj is not present the list is not altered in any way.
  58. * @param obj The item to remove from this list.
  59. * @return Return <tt>true</tt> if this list changed as a result of this call, <tt>false</tt> otherwise.
  60. */
  61. boolean remove(E obj);
  62. /**
  63. * Return a sublist of elements in this list from <tt>start</tt> inclusive to <tt>stop</tt> exclusive.
  64. * This list is not changed as a result of this call.
  65. * <br>pre: <tt>0 <= start < size(), start <= stop <= size()</tt>
  66. * <br>post: return a list whose size is stop - start and contains the elements at positions start through stop - 1 in this list.
  67. * @param start index of the first element of the sublist.
  68. * @param stop stop - 1 is the index of the last element of the sublist.
  69. * @return a list with <tt>stop - start</tt> elements, The elements are from positions <tt>start</tt> inclusive to
  70. * <tt>stop</tt> exclusive in this list.
  71. */
  72. IList<E> getSubList(int start, int stop);
  73. /**
  74. * Return the size of this list. In other words the number of elements in this list.
  75. * <br>pre: none
  76. * <br>post: return the number of items in this list
  77. * @return the number of items in this list
  78. */
  79. int size();
  80. /**
  81. * Find the position of an element in the list.
  82. * <br>pre: none
  83. * <br>post: return the index of the first element equal to item
  84. * or -1 if item is not present
  85. * @param item the element to search for in the list
  86. * @return return the index of the first element equal to item or a -1 if item is not present
  87. */
  88. int indexOf(E item);
  89. /**
  90. * find the position of an element in the list starting at a specified position.
  91. * <br>pre: 0 <= pos < size()
  92. * <br>post: return the index of the first element equal to item starting at pos
  93. * or -1 if item is not present from position pos onward
  94. * @param item the element to search for in the list
  95. * @param pos the position in the list to start searching from
  96. * @return starting from the specified position return the index of the first element equal to item or a -1 if item is not present between pos and the end of the list
  97. */
  98. int indexOf(E item, int pos);
  99. /**
  100. * return the list to an empty state.
  101. * <br>pre: none
  102. * <br>post: size() = 0
  103. */
  104. void makeEmpty();
  105. /**
  106. * return an Iterator for this list.
  107. * <br>pre: none
  108. * <br>post: return an Iterator object for this List
  109. */
  110. Iterator<E> iterator();
  111. /**
  112. * Remove all elements in this list from <tt>start</tt> inclusive to <tt>stop</tt> exclusive.
  113. * <br>pre: <tt>0 <= start < size(), start <= stop <= size()</tt>
  114. * <br>post: <tt>size() = old size() - (stop - start)</tt>
  115. * @param start position at beginning of range of elements to be removed
  116. * @param stop stop - 1 is the position at the end of the range of elements to be removed
  117. */
  118. void removeRange(int start, int stop);
  119. /**
  120. * Return a String version of this list enclosed in
  121. * square brackets, []. Elements are in
  122. * are in order based on position in the
  123. * list with the first element
  124. * first. Adjacent elements are seperated by comma's
  125. * @return a String representation of this IList
  126. */
  127. public String toString();
  128. /**
  129. * Determine if this IList is equal to other. Two
  130. * ILists are equal if they contain the same elements
  131. * in the same order.
  132. * @return true if this IList is equal to other, false otherwise
  133. */
  134. public boolean equals(Object other);
  135. }