pt.ua.base
Class Indexable<T>

java.lang.Object
  extended by pt.ua.base.Listable<T>
      extended by pt.ua.base.Indexable<T>
Direct Known Subclasses:
Queue, Set, Stack

public abstract class Indexable<T>
extends Listable<T>

Generic indexable list.

invariant: Listable

This class follows DbC(tm) methodology. Where possible, contracts are implement with JML and native's Java assert.

Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
Indexable()
           
 
Method Summary
abstract  Indexable<T> deepClone()
          Clones current list.
 ImmutableList<T> headList(int end)
          Extracts the elements contained in the interval [0, end[.
abstract  T itemAt(int idx)
          Returns the element of the list at the idx position.
 ImmutableList<T> subList(int start, int end)
          Extracts the elements contained in the interval [start, end[.
 ImmutableList<T> tailList(int start)
          Extracts the elements contained in the interval [start, size()[.
 Array<T> toArray()
          Extracts all the elements of the list.
 ImmutableList<T> toList()
          Extracts all the elements of the list.
 java.lang.String toString()
          Returns a String with all the list elements separated with a space.
 
Methods inherited from class pt.ua.base.Listable
isEmpty, isFull, isLimited, maxSize, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Indexable

public Indexable()
Method Detail

itemAt

public abstract T itemAt(int idx)
Returns the element of the list at the idx position.

requires: idx >= 0 && idx < size()

Parameters:
idx - the index
Returns:
the element

deepClone

public abstract Indexable<T> deepClone()
Description copied from class: Listable
Clones current list.

ensures: \result.size() == size()

Specified by:
deepClone in class Listable<T>
Returns:
a deep clone of current list

toList

public ImmutableList<T> toList()
Description copied from class: Listable
Extracts all the elements of the list.

ensures: \result.size == size()

Specified by:
toList in class Listable<T>
Returns:
an immutable list with all the list's elements

toArray

public Array<T> toArray()
Description copied from class: Listable
Extracts all the elements of the list.

ensures: \result.size() == size()

Specified by:
toArray in class Listable<T>
Returns:
an array with all the list's elements

subList

public ImmutableList<T> subList(int start,
                                int end)
Extracts the elements contained in the interval [start, end[.

requires: start >= 0 && start <= size()
requires: end >= 0 && end <= size()

ensures: \result.size == end-start

Parameters:
start - the start index
end - the first index after the last selected element
Returns:
an immutable list with the specified elements

headList

public ImmutableList<T> headList(int end)
Extracts the elements contained in the interval [0, end[.

requires: end >= 0 && end <= size()

ensures: \result.size == end

Parameters:
end - the first index after the last selected element
Returns:
an immutable list with the specified elements

tailList

public ImmutableList<T> tailList(int start)
Extracts the elements contained in the interval [start, size()[.

requires: start >= 0 && start <= size()

ensures: \result.size == size()-start

Parameters:
start - the start index
Returns:
an immutable list with the specified elements

toString

public java.lang.String toString()
Returns a String with all the list elements separated with a space.

Overrides:
toString in class java.lang.Object
Returns:
the complete list as a string