pt.ua.base
Class AssociativeArray<K,E>

java.lang.Object
  extended by pt.ua.base.Listable<K>
      extended by pt.ua.base.AssociativeArray<K,E>
Direct Known Subclasses:
HashTableChainingAssociativeArray

public abstract class AssociativeArray<K,E>
extends Listable<K>

Generic associative array module.

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
AssociativeArray()
           
 
Method Summary
abstract  void clear()
          Empties the associative array.
 void copy(AssociativeArray<K,E> other)
          Copies an associative array to this associative array (deep copy).
abstract  AssociativeArray<K,E> deepClone()
          Clones current list.
abstract  boolean exists(K key)
          Checks if key exists in the associative array.
abstract  E get(K key)
          Gets the element value associated with value key.
 boolean isFull()
          Queries the list fullness.
 boolean isLimited()
          Checks if list is unbounded.
abstract  Array<K> keysToArray()
          Extracts all keys to an array.
abstract  ImmutableList<K> keysToList()
          Extracts all keys to an immutable list.
 int maxSize()
          The list maximum number of elements.
abstract  void remove(K key)
          Removes key and its associated element value from the array.
abstract  void set(K key, E elem)
          Associates value elem with value key.
 Array<K> toArray()
          Extracts all the elements of the list.
 ImmutableList<K> toList()
          Extracts all the elements of the list.
 
Methods inherited from class pt.ua.base.Listable
isEmpty, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssociativeArray

public AssociativeArray()
Method Detail

isLimited

public boolean isLimited()
Description copied from class: Listable
Checks if list is unbounded.

Specified by:
isLimited in class Listable<K>
Returns:
true if list is unbounded, false otherwise

maxSize

public int maxSize()
Description copied from class: Listable
The list maximum number of elements.

requires: isLimited()

Specified by:
maxSize in class Listable<K>
Returns:
list's size

copy

public void copy(AssociativeArray<K,E> other)
Copies an associative array to this associative array (deep copy).

requires: other != null

Parameters:
other - the associative array to copy from

deepClone

public abstract AssociativeArray<K,E> deepClone()
Description copied from class: Listable
Clones current list.

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

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

set

public abstract void set(K key,
                         E elem)
Associates value elem with value key. If key did not exist, adds a new association, otherwise attaches existing key to a new element value.

requires: key != null

ensures: exists(key)
ensures: get(key) == elem
ensures: \old(exists(key)) ==> (size() == \old(size()))
ensures: \old(!exists(key)) ==> (size() == \old(size()) + 1)

Parameters:
key - the key
elem - the element

get

public abstract E get(K key)
Gets the element value associated with value key.

requires: key != null
requires: exists(key)

Parameters:
key - the key
Returns:
the element

remove

public abstract void remove(K key)
Removes key and its associated element value from the array.

requires: key != null
requires: exists(key)

ensures: !exists(key)
ensures: size() == \old(size()) - 1

Parameters:
key - the key to be removed

exists

public abstract boolean exists(K key)
Checks if key exists in the associative array.

Returns:
true if key exists, false otherwise

isFull

public boolean isFull()
Description copied from class: Listable
Queries the list fullness.

Specified by:
isFull in class Listable<K>
Returns:
true if list is full, false otherwise

keysToArray

public abstract Array<K> keysToArray()
Extracts all keys to an array. Implements: toArray().

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

Returns:
an array with all the associative array keys

toArray

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

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

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

keysToList

public abstract ImmutableList<K> keysToList()
Extracts all keys to an immutable list. Implements: toList().

ensures: \result.size == size()

Returns:
an array with all the associative array keys

toList

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

ensures: \result.size == size()

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

clear

public abstract void clear()
Empties the associative array.

ensures: isEmpty()