T
- the type of a matrix elementpublic abstract class Matrix<T>
extends java.lang.Object
implements java.io.Serializable
a(0 0)
is the top left element
and a(n-1 m-1)
is the bottom right element of a matrix a
.Modifier and Type | Field and Description |
---|---|
protected int |
m
the number of columns
|
protected int |
n
the number of rows
|
Constructor and Description |
---|
Matrix(int n,
int m)
Creates a new matrix of size
n x m and a default element value of null . |
Matrix(int n,
int m,
T defValue)
Creates a new matrix of size
n x m . |
Modifier and Type | Method and Description |
---|---|
abstract Matrix<T> |
clone()
Clones the matrix meaning that it is returned a shallow copy of
this Matrix instance
(the elements themselves are not copied/cloned). |
static <T> void |
copy(Matrix<T> source,
Matrix<T> dest)
Copies the elements of one matrix (source) to another matrix (destination).
|
boolean |
equals(Matrix<?> matrix)
Indicates whether this matrix equals the specified matrix.
|
boolean |
equals(java.lang.Object matrix)
Indicates whether this matrix equals the specified matrix.
|
T |
get(int i,
int j)
Gets the value at
a(i j) . |
int |
getColumnCount()
Gets the number of columns this matrix has.
|
int |
getRowCount()
Gets the number of rows this matrix has.
|
boolean |
isInDimension(int i,
int j)
Indicates whether the row index
i an the column index j are in the dimension of the matrix
meaning more formally: (i >= 0 && i < getRowCount()) && (j >= 0 && j < getColumnCount()) . |
boolean |
isSquare()
Indicates whether it is a square matrix.
|
void |
set(int i,
int j,
T value)
Sets the element at
a(i j) of the matrix. |
void |
set(T[][] elements)
Sets the elements of the matrix.
|
java.lang.String |
toString() |
protected final int n
protected final int m
public Matrix(int n, int m) throws java.lang.IllegalArgumentException
n
x m
and a default element value of null
.n
- the number of rowsm
- the number of columnsjava.lang.IllegalArgumentException
- < 1
< 1
public Matrix(int n, int m, T defValue) throws java.lang.IllegalArgumentException
n
x m
.n
- the number of rowsm
- the number of columnsdefValue
- the default element valuejava.lang.IllegalArgumentException
- < 1
< 1
public T get(int i, int j) throws java.lang.IndexOutOfBoundsException
a(i j)
.
a(0 0)
is the top left element
and a(n-1 m-1)
is the bottom right element of the matrix a
.i
- the index of the rowj
- the index of the columnjava.lang.IndexOutOfBoundsException
- public void set(int i, int j, T value) throws java.lang.IndexOutOfBoundsException
a(i j)
of the matrix.
a(0 0)
is the top left element
and a(n-1 m-1)
is the bottom right element of the matrix a
.i
- the index of the rowj
- the index of the columnvalue
- the valuejava.lang.IndexOutOfBoundsException
- isInDimension(int, int)
public void set(T[][] elements) throws java.lang.IllegalArgumentException
elements
- the elementsjava.lang.IllegalArgumentException
- public final int getRowCount()
public final int getColumnCount()
public final boolean isInDimension(int i, int j)
i
an the column index j
are in the dimension of the matrix
meaning more formally: (i >= 0 && i < getRowCount()) && (j >= 0 && j < getColumnCount())
.
a(0 0)
is the top left element
and a(n-1 m-1)
is the bottom right element of the matrix a
.i
- the row indexj
- the column indextrue
if the indices are in the dimension of the matrix otherwise false
public final boolean isSquare()
true
if the matrix is square otherwise false
public abstract Matrix<T> clone()
this
Matrix
instance
(the elements themselves are not copied/cloned).clone
in class java.lang.Object
this
matrixpublic boolean equals(java.lang.Object matrix)
equals
in class java.lang.Object
matrix
- the matrix to be compared withtrue
if both matrices are equal otherwise false
public boolean equals(Matrix<?> matrix)
matrix
- the matrix to be compared withtrue
if both matrices are equal otherwise false
public java.lang.String toString()
toString
in class java.lang.Object
public static <T> void copy(Matrix<T> source, Matrix<T> dest) throws java.lang.IllegalArgumentException
source
- the source matrix whose elements should be copieddest
- the destination matrixjava.lang.IllegalArgumentException
-