structure
Class Matrix

java.lang.Object
  extended by structure.Matrix

public class Matrix
extends java.lang.Object

An implementation of rectangular vectors. This implementation of a Matrix is minimal. Few operations are provided, and no support for mathematical operations is considered.


Field Summary
protected  int height
           
protected  Vector rows
           
protected  int width
           
 
Constructor Summary
Matrix()
          Construct an empty matrix.
Matrix(int h, int w)
          Constructs a matrix such that all values are null.
 
Method Summary
 void addCol(int c)
          Add a new column, whose index will be c.
 void addRow(int r)
          Add a new row, whose index will be r.
 java.lang.Object get(int row, int col)
          Fetch an element from the matrix.
 int height()
          Return the height of the matrix.
 Vector removeCol(int c)
          Remove a column, whose index is c.
 Vector removeRow(int r)
          Remove the row whose index is r.
 void set(int row, int col, java.lang.Object value)
          Change the value at location (row, col)
 java.lang.String toString()
          Construct a string representation of the matrix.
 int width()
          Return the width of the matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

height

protected int height

width

protected int width

rows

protected Vector rows
Constructor Detail

Matrix

public Matrix()
Construct an empty matrix.

Postcondition:
constructs empty matrix

Matrix

public Matrix(int h,
              int w)
Constructs a matrix such that all values are null.

Parameters:
h - Height of the matrix.
w - Width of the matrix.
Precondition:
h >= 0, w >= 0;
Postcondition:
constructs an h row by w column matrix
Method Detail

get

public java.lang.Object get(int row,
                            int col)
Fetch an element from the matrix.

Parameters:
row - The row of the element
col - The column of the element
Returns:
Object located at matrix position (row, col)
Precondition:
0 <= row < height(), 0 <= col < width()
Postcondition:
returns object at (row, col)

set

public void set(int row,
                int col,
                java.lang.Object value)
Change the value at location (row, col)

Parameters:
value - The new Object reference (possibly null).
row - The row of the value to be changed.
col - The column of the value to be changed.
Precondition:
0 <= row < height(), 0 <= col < width()
Postcondition:
changes location (row, col) to value

addRow

public void addRow(int r)
Add a new row, whose index will be r.

Parameters:
r - The index of the newly inserted row.
Precondition:
0 <= r < height()
Postcondition:
inserts row of null values to be row r

addCol

public void addCol(int c)
Add a new column, whose index will be c.

Parameters:
c - The index of the newly inserted column.
Precondition:
0 <= c < width()
Postcondition:
inserts column of null values to be column c

removeRow

public Vector removeRow(int r)
Remove the row whose index is r. The row is returned as a vector.

Parameters:
r - The index of the to-be-removed row.
Returns:
A vector of values once in the row.
Precondition:
0 <= r < height()
Postcondition:
removes row r and returns it as a Vector

removeCol

public Vector removeCol(int c)
Remove a column, whose index is c.

Parameters:
c - The index of the column to be removed.
Returns:
A vector of the values removed.
Precondition:
0 <= c < width()
Postcondition:
removes column c and returns it as a vector

width

public int width()
Return the width of the matrix.

Returns:
The number of columns in the matrix.
Postcondition:
returns number of columns in matrix

height

public int height()
Return the height of the matrix.

Returns:
The number of rows in the matrix.
Postcondition:
returns number of rows in matrix

toString

public java.lang.String toString()
Construct a string representation of the matrix.

Overrides:
toString in class java.lang.Object
Returns:
A string, representing the matrix.
Postcondition:
returns string description of matrix.