SimpleList.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * This interface describes a simple list with operations
  3. * to add and remove elements from either end of the list.
  4. *
  5. * @param <E> type of elements stored in the list
  6. */
  7. public interface SimpleList<E> {
  8. /**
  9. * Adds the given element to the start of the list.
  10. * @param elem element to add
  11. */
  12. public void addFirst(E elem);
  13. /**
  14. * Adds the given element to the end of the list.
  15. * @param elem element to add
  16. */
  17. public void addLast(E elem);
  18. /**
  19. * Removes the first element from the list.
  20. * @return element that was removed
  21. * @throws NoSuchElementException if there is no first element
  22. */
  23. public E removeFirst();
  24. /**
  25. * Removes the last element from the list.
  26. * @return element that was removed
  27. * @throws NoSuchElementException if there is no last element
  28. */
  29. public E removeLast();
  30. /**
  31. * Returns the size of the list (i.e. the number of elements
  32. * stored in the list.
  33. * @return size of list
  34. */
  35. public int size();
  36. /**
  37. * Returns the element in the list at the given index.
  38. * @param index index of element to return
  39. * @return element at given index
  40. * @throws IndexOutOfBoundsException if given index is invalid
  41. */
  42. public E get(int index);
  43. /**
  44. * Returns the list as a string. The string contains all of the elements
  45. * in order from first to last.
  46. * @return list as a string
  47. */
  48. public String toString();
  49. /**
  50. * Returns true of this list is equal to the given list.
  51. * Two lists are equal if they contain the same elements in the same order.
  52. * @param otherList list to compare to this list
  53. * @return true if lists are equal
  54. */
  55. public boolean equals(SimpleList<E> otherList);
  56. }