ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.collections
Class AbstractMatrix<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by umontreal.iro.lecuyer.collections.AbstractMatrix<E>
Type Parameters:
E - the type of the elements.
All Implemented Interfaces:
Iterable<E>, Collection<E>, Matrix<E>
Direct Known Subclasses:
DenseMatrix

public abstract class AbstractMatrix<E>
extends AbstractCollection<E>
implements Matrix<E>

Provides default implementation for most methods of the Matrix interface.


Field Summary
protected  int modCount
          This must be incremented each time Matrix.setRows(int) or Matrix.setColumns(int) modify the number of rows or columns.
 
Constructor Summary
AbstractMatrix()
           
 
Method Summary
 List<E> asList()
          Returns a list using size() to get the number of elements, and Matrix.get(int, int) to access elements.
 boolean equals(Object o)
          Compares the specified object with this matrix for equality.
 int hashCode()
          Returns the hash code value for the matrix.
 boolean isEmpty()
          Returns true if Matrix.rows() or Matrix.columns() return 0.
 Iterator<E> iterator()
          Constructs and returns an iterator traversing the elements of this matrix rowise.
 E set(int r, int c, E value)
          Sets the element at index (r, c) of the matrix to value, and returns the element previously at that position.
 int size()
          Returns the product of Matrix.rows() and Matrix.columns().
 Object[][] to2DArray()
          Returns a 2D array containing the elements of this matrix in the proper sequence.
 E[][] to2DArray(E[][] array)
          Returns a 2D array containing the elements of this matrix in the proper sequence; the runtime type of the returned array is the same as the runtime type of the given array.
 String toString()
           
 List<E> viewColumn(int c)
          Returns a list using Matrix.rows() to get the number of elements, and Matrix.get(int, int) to access elements.
 Matrix<E> viewPart(int fromRow, int fromColumn, int toRow, int toColumn)
          Returns a view of a portion of this matrix containing rows fromRow (inclusive) to toRow (exclusive), and columns fromColumn (inclusive) to toColumn (exclusive).
 List<E> viewRow(int r)
          Returns a list using Matrix.columns() to get the number of elements, and Matrix.get(int, int) to access elements.
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface umontreal.iro.lecuyer.collections.Matrix
columns, get, rows, setColumns, setRows
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

modCount

protected int modCount
This must be incremented each time Matrix.setRows(int) or Matrix.setColumns(int) modify the number of rows or columns.

Constructor Detail

AbstractMatrix

public AbstractMatrix()
Method Detail

asList

public List<E> asList()
Returns a list using size() to get the number of elements, and Matrix.get(int, int) to access elements.

Specified by:
asList in interface Matrix<E>
Returns:
the list view.

viewRow

public List<E> viewRow(int r)
Returns a list using Matrix.columns() to get the number of elements, and Matrix.get(int, int) to access elements.

Specified by:
viewRow in interface Matrix<E>
Parameters:
r - the index of the row to get a view for.
Returns:
the view of the selected row.

viewColumn

public List<E> viewColumn(int c)
Returns a list using Matrix.rows() to get the number of elements, and Matrix.get(int, int) to access elements.

Specified by:
viewColumn in interface Matrix<E>
Parameters:
c - the index of the column to get a view for.
Returns:
the view of the selected column.

viewPart

public Matrix<E> viewPart(int fromRow,
                          int fromColumn,
                          int toRow,
                          int toColumn)
Description copied from interface: Matrix
Returns a view of a portion of this matrix containing rows fromRow (inclusive) to toRow (exclusive), and columns fromColumn (inclusive) to toColumn (exclusive). The bahavior of the returned matrix is undefined if the dimensions of the backing matrix are changed. This method is optional, and throws an UnsupportedOperationException if not implemented.

Specified by:
viewPart in interface Matrix<E>
Parameters:
fromRow - the starting row.
fromColumn - the ending row.
toRow - the starting column.
toColumn - the ending column.
Returns:
the view of the matrix.

set

public E set(int r,
             int c,
             E value)
Description copied from interface: Matrix
Sets the element at index (r, c) of the matrix to value, and returns the element previously at that position. This method is optional, and throws an UnsupportedOperationException if not implemented.

Specified by:
set in interface Matrix<E>
Parameters:
r - the row index.
c - the column index.
value - the value of the element.
Returns:
the previous value of the element.

size

public int size()
Returns the product of Matrix.rows() and Matrix.columns().

Specified by:
size in interface Collection<E>
Specified by:
size in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Returns true if Matrix.rows() or Matrix.columns() return 0.

Specified by:
isEmpty in interface Collection<E>
Overrides:
isEmpty in class AbstractCollection<E>

iterator

public Iterator<E> iterator()
Description copied from interface: Matrix
Constructs and returns an iterator traversing the elements of this matrix rowise.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Matrix<E>
Specified by:
iterator in class AbstractCollection<E>
Returns:
the constructed iterator.

equals

public boolean equals(Object o)
Description copied from interface: Matrix
Compares the specified object with this matrix for equality. Returns true if and only if the specified object is also a matrix, both matrices have the same dimensions, and all corresponding pairs of elements in the two matrices are equal. (Two elements e1 and e2 are equal if (e1 == null ? e2 == null : e1.equals (e2)).) In other words, two matrices are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the Matrix interface.

Specified by:
equals in interface Collection<E>
Specified by:
equals in interface Matrix<E>
Overrides:
equals in class Object

hashCode

public int hashCode()
Description copied from interface: Matrix
Returns the hash code value for the matrix. The hash code of a matrix is defined to be 31*(31*R + C) + H, where H is the hash code of the list view returned by Matrix.asList(). This ensures that matrix1.equals (matrix2) implies that matrix1.hashCode() == matrix2.hashCode() for any two matrices, matrix1 and matrix2, as required by the general contract of Object.hashCode.

Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface Matrix<E>
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class AbstractCollection<E>

to2DArray

public E[][] to2DArray(E[][] array)
Description copied from interface: Matrix
Returns a 2D array containing the elements of this matrix in the proper sequence; the runtime type of the returned array is the same as the runtime type of the given array.

Specified by:
to2DArray in interface Matrix<E>
Parameters:
array - the array to use.
Returns:
the array containing the elements of this matrix.

to2DArray

public Object[][] to2DArray()
Description copied from interface: Matrix
Returns a 2D array containing the elements of this matrix in the proper sequence.

Specified by:
to2DArray in interface Matrix<E>
Returns:
the array containing the elements of this matrix.

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.