|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectbeowulf.model.Matrix
This class represents a two dimensional grid of objects. Often, this is
implemented using a java.util.Vector of java.util.Vector objects. This class
can contain references to any object. It is not thread safe - there
are no synchronized methods. This matrix can expand itself (via the right
method calls), but it has no way of collapsing itself back down. In other
words, it is up to the programmer to manage how the data is stored in the
Matrix.
| Field Summary | |
protected Object[][] |
data
The actual data that the matrix is holding. |
protected int |
numCols
The number of columns in the matrix. |
protected int |
numRows
The number of rows in the matrix. |
| Constructor Summary | |
Matrix()
Creates a new 1x1 matrix. |
|
Matrix(int size)
Creates a new sizexsize matrix. |
|
Matrix(int rows,
int cols)
Creates a new rowsxcols matrix. |
|
| Method Summary | |
void |
add(int row,
int col,
Object value)
This method performs just as put(int, int, Object) but does
not fail when row or col are out of bounds. |
boolean |
add(Object o)
This operation is not implemented since it does not make semantic sense to add an element to a matrix without specifying the location to which it will be added. |
boolean |
addAll(Collection c)
This operation is not implemented since it does not make semantic sense to add a collection of elements to a matrix without specifying the location to which they will be added. |
void |
clear()
This method sets the matrix back to a 1x1 matrix with the default value as the only entry. |
boolean |
contains(Object o)
This method will return true if o is contained somewhere
within the matrix. |
boolean |
containsAll(Collection c)
This method takes in a java.util.Collection of elements
and returns true if and only if each element of that Collection
is contained in this matrix. |
void |
expandBy(int newAmount)
This method expands the matrix by newAmount in each
direction. |
void |
expandBy(int rowAmount,
int colAmount)
This method expands the matrix by the indicated amount in each direction. |
void |
expandTo(int newSize)
This method ensures that this matrix is at least newSizexnewSize. |
void |
expandTo(int rowSize,
int colSize)
This method ensures that this matrix is at least rowSizexcolSize. |
Object |
get(int row,
int col)
This method returns the object at the specified position. |
int |
getCols()
Returns the number of columns in this matrix. |
Object |
getDefaultValue()
This method will return the default value for any given subclass of matrix. |
int |
getRows()
Returns the number of rows in this matrix. |
boolean |
isEmpty()
This method returns true if and only if ever element of the matrix is empty ( null). |
Iterator |
iterator()
This implementation of the method will return an iterator that iterates over the elements of the matrix in row major order and does not return null elements. |
void |
put(int row,
int col,
Object value)
Sets the value at [ row][col] to be
value. |
void |
remove(int element)
This is equivalent to calling remove(i, j) for all
combinations of i and j where either is equal
to element. |
void |
remove(int row,
int column)
Sets the element at [ row][column] to be the
default value. |
boolean |
remove(Object o)
This method will remove an object o if it exists in this
matrix. |
boolean |
removeAll(Collection c)
This method will remove all of the elements of c from this
matrix. |
void |
removeCol(int col)
This is equivalent to calling remove(i, j) for all
combinations of i and j where j
is equal to col. |
void |
removeRow(int row)
This is equivalent to calling remove(i, j) for all
combinations of i and j where i
is equal to row. |
boolean |
retainAll(Collection c)
This method will iterate over all of the elements of the matrix and will keep an element in the matrix if and only if the matrix element is in c. |
int |
size()
Returns the number of elements in this matrix. |
Object[] |
toArray()
This will convert the entire matrix into an array. |
Object[] |
toArray(Object[] a)
This method will place all of the elements of this matrix into a single array and return it. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
equals, hashCode |
| Field Detail |
protected Object[][] data
protected int numRows
protected int numCols
| Constructor Detail |
public Matrix()
public Matrix(int size)
sizexsize matrix.
size - The size of the new matrix.
public Matrix(int rows,
int cols)
rowsxcols matrix.
rows - The number of rows in the new matrix.cols - The number of columns in the new matrix.| Method Detail |
public int getRows()
public int getCols()
public void removeRow(int row)
remove(i, j) for all
combinations of i and j where i
is equal to row.
row - The row to zero out.public void removeCol(int col)
remove(i, j) for all
combinations of i and j where j
is equal to col.
col - The column to zero out.public void remove(int element)
remove(i, j) for all
combinations of i and j where either is equal
to element.
element - The row/column to zero out.
public void remove(int row,
int column)
row][column] to be the
default value.
row - The row of the element to remove.column - The column of the element to remove.public void expandTo(int newSize)
newSizexnewSize. If this is smaller than the
current size, the elements with the higher valued indices are dropped.
If this is bigger than the current size, the new spots are filled in
with the default value.
newSize - The minimum size of the matrix.
public void expandTo(int rowSize,
int colSize)
rowSizexcolSize. If this is smaller than the
current size, the elements with the higher valued indices are dropped.
If this is bigger than the current size, the new spots are filled in
with the default value.
rowSize - The minimum number of rows in the matrix.colSize - The minimum number of columns in the matrix.public void expandBy(int newAmount)
newAmount in each
direction. The new spots are set to null.
newAmount - The amount by which the matrix should expand.
public void expandBy(int rowAmount,
int colAmount)
rowAmount - The number of new rows to add.colAmount - The number of new columns to add.
public Object get(int row,
int col)
row or col are out of bounds, an exception is
thrown. The return value might be null.
row - The row index of the value.col - The column index of the value.
public void put(int row,
int col,
Object value)
row][col] to be
value. If either row or col are
out of bounds, and exception will be thrown.
row - The row index of the value to set.col - The column index of the value to set.value - The new value of the indicated position.
public void add(int row,
int col,
Object value)
put(int, int, Object) but does
not fail when row or col are out of bounds.
Rather, it will expand to the size implied by row and
col until the indicated location exists. The value at that
point will then be set.
row - The row index of the value to set.col - The column index of the value to set.value - The new value of the indicated position.public Object getDefaultValue()
null is always the default
value.
null.public Object[] toArray(Object[] a)
a If the elements of this matrix will fit entirely
into a, it is used. Otherwise a new array is allocated and
the data are copied into this new array. If the given array is
null, a NullPointerException will be thrown.
toArray in interface Collectiona - the array into which the elements of the Vector are to be
stored, if it is big enough; otherwise, a new array of the same runtime
type is allocated for this purpose.
ArrayStoreException - the runtime type of a is not a supertype
of the runtime type of every element in this Vector.
NullPointerException - if the given array is null.public Object[] toArray()
null values are allowed in the returned array.
toArray in interface Collectionpublic int size()
null elements.
size in interface Collectionpublic boolean isEmpty()
null).
isEmpty in interface Collectionpublic boolean add(Object o)
add in interface Collectiono - The object to be added.
public boolean addAll(Collection c)
addAll in interface Collectionc - The collection of elements to be added.
public boolean remove(Object o)
o if it exists in this
matrix. .equals(Object) will be used to test equality,
and if such an element exists, remove(int, int) will be
called to remove the element from its spot in the matrix. The return
value will indicate whether or not the matrix changed as a result of
this operation. Only the first occurance of o will be
removed.
remove in interface Collectiono - The object to remove.
public void clear()
clear in interface Collectionpublic boolean retainAll(Collection c)
c. The return value will indicate
whether or not the matrix changed as a result of this operation.
The element will be removed by calling remove(int i, int j)
. null elements will be ignored.
retainAll in interface Collectionc - The collection of elements to keep.
public boolean removeAll(Collection c)
c from this
matrix. This is equivalent to calling remove(Object) on
each element of c. The return value will indicate whether
or not the return value changed as a result of this operation. Element
removal will be implemented by calling .remove(Object o)
with the element to be removed as a parameter.
removeAll in interface Collectionc - The collection of elements to remove from this matrix.
public boolean contains(Object o)
o is contained somewhere
within the matrix. .equals(Object) will be used to test
for equality.
contains in interface Collectiono - The object to search for in the matrix.
public boolean containsAll(Collection c)
java.util.Collection of elements
and returns true if and only if each element of that Collection
is contained in this matrix. .equals(Object o) is
used to test for equality.
containsAll in interface Collectionc - The collection of elements that this method will
search for in the matrix.
c is contained
in this matrix.public Iterator iterator()
remove()
operation is unsupported.
iterator in interface Collection
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||