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.


Method Index

 o at(int)
Return the element at the indicated index
 o first()
Return the first element, if it exists.
 o firstIndexOf(Object)
Find the leftmost occurrence of an element.
 o 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.
 o 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.
 o last()
Return the last element, if it exists.
 o lastIndexOf(Object)
Find the rightmost occurrence of an element.
 o 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.
 o 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.
 o replacingAt(int, Object)
Construct a new Seq that is a clone of self except that the indicated element is placed at the indicated index.
 o 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.

Methods

 o 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
 o first
 public abstract Object first() throws NoSuchElementException
Return the first element, if it exists. Behaviorally equivalent to at(0)

Throws: NoSuchElementException
if isEmpty
 o last
 public abstract Object last() throws NoSuchElementException
Return the last element, if it exists. Behaviorally equivalent to at(size()-1)

Throws: NoSuchElementException
if isEmpty
 o 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)
 
 o firstIndexOf
 public abstract int firstIndexOf(Object element)
Find the leftmost occurrence of an element. Behaviorally equivalent to firstIndexOf(element, 0)

 o 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)
 
 o lastIndexOf
 public abstract int lastIndexOf(Object element)
Find the rightmost occurrence of an element. Behaviorally equivalent to lastIndexOf(element, size()-1)

 o 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
 o 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
 o 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
 o 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