pt.ua.base
Class Array<T>

java.lang.Object
  extended by pt.ua.base.Array<T>

public class Array<T>
extends java.lang.Object

Generic array module.

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
Array(int size)
          Creates an array with size elements.
 
Method Summary
 boolean equals(Array<T> other)
          Queries equality with other array.
 T get(int idx)
          Gets array's element at idx position.
 void set(int idx, T elem)
          Sets array's element at idx position.
 int size()
          The array's immutable size
 void sort()
          Sort array's elements (using their natural orderig).
 void sort(int fromIdx, int toIdx)
          Sort subarray's [fromIdx ; toIdx[ elements (using their natural orderig).
 java.lang.String toString()
          Returns a String with all array's elements separated with a space.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Array

public Array(int size)
Creates an array with size elements.

requires: size >= 0

Method Detail

size

public int size()
The array's immutable size


equals

public boolean equals(Array<T> other)
Queries equality with other array.

requires: other != null

Returns:
true if arrays are equal, false otherwise

get

public T get(int idx)
Gets array's element at idx position.

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

Parameters:
idx - the index
Returns:
the element

set

public void set(int idx,
                T elem)
Sets array's element at idx position.

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

Parameters:
idx - the index
elem - the element

toString

public java.lang.String toString()
Returns a String with all array's elements separated with a space.

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

sort

public void sort()
Sort array's elements (using their natural orderig).


sort

public void sort(int fromIdx,
                 int toIdx)
Sort subarray's [fromIdx ; toIdx[ elements (using their natural orderig).

requires: fromIdx >= 0 && fromIdx < size()
requires: toIdx >= fromIdx && toIdx <= size()

Parameters:
fromIdx - index of first element to sort
toIdx - index of first element NOT to sort