    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Interface collections.Seq

public interface interface Seq
extends Collection

Seqs are indexed, sequentially ordered collections. Indices are always in the range 0 .. size() -1. All accesses by index are checked, raising exceptions if the index falls out of range.

The elements() enumeration for all seqs is guaranteed to be traversed (via nextElement) in sequential order.

##

at(int)
  Return the element at the indicated index
first()
  Return the first element, if it exists.
firstIndexOf(Object)
  Find the leftmost occurrence of an element.
firstIndexOf(Object, int)
  Report the index of leftmost occurrence of an element from a given starting point, or -1 if there is no such index.
insertingAt(int, Object)
  Construct a new Seq that is a clone of self except that it adds (inserts) the indicated element at the indicated index.
last()
  Return the last element, if it exists.
lastIndexOf(Object)
  Find the rightmost occurrence of an element.
lastIndexOf(Object, int)
  Report the index of righttmost occurrence of an element from a given starting point, or -1 if there is no such index.
removingAt(int)
  Construct a new Seq that is a clone of self except that it does not contain the element at the indeicated index; all elements to its right are slided left by one.
replacingAt(int, Object)
  Construct a new Seq that is a clone of self except that the indicated element is placed at the indicated index.
subseq(int, int)
  Construct a new Seq that is a clone of self except that it does not contain the elements before index or after index+length.

##

at

     public abstract Object at(int index) throws NoSuchElementException

  Return the element at the indicated index

  Returns:
    the element at the index
  Throws: NoSuchElementException
    if index is not in range 0..size()-1

first

     public abstract Object first() throws NoSuchElementException

  Return the first element, if it exists. Behaviorally equivalent to at(0)

  Throws: NoSuchElementException
    if isEmpty

last

     public abstract Object last() throws NoSuchElementException

  Return the last element, if it exists. Behaviorally equivalent to at(size()-1)

  Throws: NoSuchElementException
    if isEmpty

firstIndexOf

     public abstract int firstIndexOf(Object element,
                                      int startingIndex)

  Report the index of leftmost occurrence of an element from a given starting point, or -1 if there is no such index.

  Parameters:
    element - the element to look for
    startingIndex - the index to start looking from. The startingIndex need not be a valid index. If less than zero it is treated as 0. If greater than or equal to size(), the result will always be -1.
  Returns:
    index such that

         let int si = max(0, startingIndex) in
          index == -1 &&
           foreach (int i in si .. size()-1) !at(index).equals(element)
          ||
          at(index).equals(element) &&
           foreach (int i in si .. index-1) !at(index).equals(element)

firstIndexOf

     public abstract int firstIndexOf(Object element)

  Find the leftmost occurrence of an element. Behaviorally equivalent to firstIndexOf(element, 0)

lastIndexOf

     public abstract int lastIndexOf(Object element,
                                     int startingIndex)

  Report the index of righttmost occurrence of an element from a given starting point, or -1 if there is no such index.

  Parameters:
    element - the element to look for
    startingIndex - the index to start looking from. The startingIndex need not be a valid index. If less than zero the result will always be -1. If greater than or equal to size(), it is treated as size()-1.
  Returns:
    index such that

         let int si = min(size()-1, startingIndex) in
          index == -1 &&
           foreach (int i in 0 .. si) !at(index).equals(element)
          ||
          at(index).equals(element) &&
           foreach (int i in index+1 .. si) !at(index).equals(element)

lastIndexOf

     public abstract int lastIndexOf(Object element)

  Find the rightmost occurrence of an element. Behaviorally equivalent to lastIndexOf(element, size()-1)

subseq

     public abstract Seq subseq(int index,
                                int length) throws NoSuchElementException

  Construct a new Seq that is a clone of self except that it does not contain the elements before index or after index+length. If length is less than or equal to zero, return an empty Seq.

  Parameters:
    index - of the element that will be the 0th index in new Seq
    length - the number of elements in the new Seq
  Returns:
    new seq such that

         s.size() == max(0, length) &&
         foreach (int i in 0 .. s.size()-1) s.at(i).equals(at(i+index));

  Throws: NoSuchElementException
    if index is not in range 0..size()-1

insertingAt

     public abstract Seq insertingAt(int index,
                                     Object element) throws IllegalElementException, NoSuchElementException

  Construct a new Seq that is a clone of self except that it adds (inserts) the indicated element at the indicated index.

  Parameters:
    index - the index at which the new element will be placed
    element - The element to insert in the new collection
  Returns:
    new seq s, such that

          s.at(index) == element &&
          foreach (int i in 1 .. s.size()-1) s.at(i).equals(at(i-1));

  Throws: NoSuchElementException
    if index is not in range 0..size()-1

replacingAt

     public abstract Seq replacingAt(int index,
                                     Object element) throws IllegalElementException, NoSuchElementException

  Construct a new Seq that is a clone of self except that the indicated element is placed at the indicated index.

  Parameters:
    index - the index at which to replace the element
    element - The new value of at(index)
  Returns:
    new seq, s, such that

          s.at(index) == element &&
          foreach (int i in 0 .. s.size()-1)
             (i != index) --> s.at(i).equals(at(i));

  Throws: NoSuchElementException
    if index is not in range 0..size()-1

removingAt

     public abstract Seq removingAt(int index) throws NoSuchElementException

  Construct a new Seq that is a clone of self except that it does not contain the element at the indeicated index; all elements to its right are slided left by one.

  Parameters:
    index - the index at which to remove an element
  Returns:
    new seq such that

          foreach (int i in 0.. index-1) s.at(i).equals(at(i)); &&
          foreach (int i in index .. s.size()-1) s.at(i).equals(at(i+1));

  Throws: NoSuchElementException
    if index is not in range 0..size()-1

    All Packages  Class Hierarchy  This Package  Previous  Next  Index