|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.mathematics.algebraic.AbstractHypermatrix
org.jscience.mathematics.algebraic.AbstractMatrix
org.jscience.mathematics.algebraic.matrices.BooleanMatrix
public class BooleanMatrix
Fixed sized (non resizable) n*m boolean matrix. A boolean matrix has a number of columns and rows, which are assigned upon instance construction - The matrix's size is then columns()*rows(). booleans are accessed via (column,row) coordinates.
Individual booleans can be examined, set, or cleared. Rectangular parts (boxes) can quickly be extracted, copied and replaced. Quick iteration over boxes is provided by optimized internal iterators (forEach() methods). OneBooleanMatrix may be used to modify the contents of another
BooleanMatrix through logical AND, OR, XOR and other similar operations.
Legal coordinates range from [0,0] to [columns()-1,rows()-1].
Any attempt to access a boolean at a coordinate column<0 || column>=columns() || row<0 || row>=rows() will throw an IndexOutOfBoundsException.
Operations involving two boolean matrices (like AND, OR, XOR, etc.) will throw an IllegalArgumentException if both boolean matrices do not have the same number of columns and rows.
If you need extremely quick access to individual booleans: Although getting and setting individual booleans with methods get(...) and put(...) is quick, it is even quicker (but not safe) to use getQuick(...) and putQuick(...).
Note that this implementation is not synchronized.
BooleanVector,
BitSet,
Serialized Form| Constructor Summary | |
|---|---|
BooleanMatrix(boolean[][] array)
Constructs a vector by wrapping an array. |
|
BooleanMatrix(BooleanMatrix mat)
Copy constructor. |
|
BooleanMatrix(int rows,
int columns)
Constructs a boolean matrix with a given number of columns and rows. |
|
| Method Summary | |
|---|---|
AbelianGroup.Member |
add(AbelianGroup.Member m)
Returns the addition (or) of this matrix and another. |
BooleanMatrix |
add(BooleanMatrix m)
Returns the addition (or) of this matrix and another. |
BooleanMatrix |
and(BooleanMatrix other)
Performs a logical AND of the receiver with another boolean matrix. |
BooleanMatrix |
andNot(BooleanMatrix other)
Clears all of the booleans in receiver whose corresponding boolean is set in the other boolean matrix. |
BooleanMatrix |
clear()
Clears all booleans of the receiver. |
java.lang.Object |
clone()
Clone matrix into a new matrix. |
protected void |
containsBox(int column,
int row,
int width,
int height)
Checks whether the receiver contains the given box. |
boolean |
equals(java.lang.Object obj)
Compares this object against the specified object. |
AbstractBooleanVector |
getColumn(int j)
Returns the ith column. |
Boolean |
getElement(int row,
int column)
Returns an element of this matrix. |
boolean |
getPrimitiveElement(int row,
int column)
Returns from the receiver the value of the boolean at the specified coordinate (this is the fastest way of getting an element for this kind of matrix). |
AbstractBooleanVector |
getRow(int i)
Returns the ith row. |
int |
hashCode()
Returns a hash code value for the NON EMPTY receiver. |
BooleanMatrix |
mapElements(PrimitiveMapping f)
Applies a function on all the matrix elements. |
BooleanMatrix |
multiply(BooleanMatrix m)
Returns the multiplication of this matrix and another. |
BooleanVector |
multiply(BooleanVector v)
Returns the multiplication of a vector by this matrix. |
Ring.Member |
multiply(Ring.Member m)
Returns the multiplication of this matrix and another. |
AbelianGroup.Member |
negate()
Returns the negative (not) of this matrix. |
BooleanMatrix |
not()
Performs a logical NOT on the booleans of the receiver. |
BooleanMatrix |
or(BooleanMatrix other)
Performs a logical OR of the receiver with another boolean matrix. |
BooleanMatrix |
part(int column,
int row,
int width,
int height)
Constructs and returns a new matrix with width columns and height rows which is a copy of the contents of the given box. |
void |
replaceBoxWith(int column,
int row,
int width,
int height,
boolean value)
Sets the booleans in the given box to the state specified by value. |
void |
replaceBoxWith(int column,
int row,
int width,
int height,
BooleanMatrix source,
int sourceColumn,
int sourceRow)
Replaces a box of the receiver with the contents of another matrix's box. |
VectorSpace.Member |
scalarDivide(Field.Member x)
Returns the division of this matrix by a scalar. |
BooleanMatrix |
scalarMultiply(boolean x)
Returns the multiplication (and) of this matrix by a scalar. |
Module.Member |
scalarMultiply(Ring.Member x)
Returns the multiplication (and) of this matrix by a scalar. |
void |
setAllElements(boolean b)
Sets the value of all elements of the matrix. |
void |
setColumn(int j,
AbstractBooleanVector v)
Sets the jth column. |
void |
setElement(int row,
int column,
boolean value)
Sets the boolean at the specified coordinate to the state specified by value. |
void |
setElement(int row,
int column,
Boolean value)
Sets the boolean at the specified coordinate to the state specified by value. |
void |
setRow(int i,
AbstractBooleanVector v)
Sets the ith row. |
AbelianGroup.Member |
subtract(AbelianGroup.Member m)
Returns the subtraction (or not) of this matrix by another. |
BooleanMatrix |
subtract(BooleanMatrix m)
Returns the subtraction (or not) of this matrix by another. |
BooleanVector |
toBooleanVector()
Converts the receiver to a booleanvector. |
ComplexMatrix |
toComplexMatrix()
Converts this matrix to a complex matrix. |
DoubleMatrix |
toDoubleMatrix()
Converts this matrix to a double matrix. |
IntegerMatrix |
toIntegerMatrix()
Converts this matrix to a integer matrix. |
boolean[][] |
toPrimitiveArray()
Projects the matrix to an array. |
java.lang.String |
toString()
Returns a (very crude) string representation of the receiver. |
Matrix |
transpose()
Returns the transpose of this matrix. |
int |
trueBooleans()
Returns the number of booleans currently in the true state. |
BooleanMatrix |
xor(BooleanMatrix other)
Performs a logical XOR of the receiver with another boolean matrix. |
| Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix |
|---|
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray, toArray |
| Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix |
|---|
getDimensions, numDimensions, numElements, numElements, toArray |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix |
|---|
getDimensions, numDimensions, numElements, numElements, toArray |
| Constructor Detail |
|---|
public BooleanMatrix(int rows,
int columns)
columns - the number of columns the matrix shall have.rows - the number of rows the matrix shall have.
java.lang.IllegalArgumentException - if columns < 0 || rows < 0.public BooleanMatrix(boolean[][] array)
array - an assigned valuepublic BooleanMatrix(BooleanMatrix mat)
mat - an assigned value| Method Detail |
|---|
public IntegerMatrix toIntegerMatrix()
public DoubleMatrix toDoubleMatrix()
public ComplexMatrix toComplexMatrix()
public int trueBooleans()
public boolean getPrimitiveElement(int row,
int column)
column - the index of the column-coordinate.row - the index of the row-coordinate.
java.lang.IndexOutOfBoundsException - if column<0 || column>=columns() || row<0 || row>=rows()
public Boolean getElement(int row,
int column)
getElement in interface Matrixcolumn - the index of the column-coordinate.row - the index of the row-coordinate.
IllegalDimensionException - If attempting to access an invalid element.public AbstractBooleanVector getRow(int i)
getRow in interface Matrixi - DOCUMENT ME!
public AbstractBooleanVector getColumn(int j)
getColumn in interface Matrixj - DOCUMENT ME!
public void setRow(int i,
AbstractBooleanVector v)
public void setColumn(int j,
AbstractBooleanVector v)
protected void containsBox(int column,
int row,
int width,
int height)
public BooleanMatrix part(int column,
int row,
int width,
int height)
column - the index of the column-coordinate.row - the index of the row-coordinate.width - the width of the box.height - the height of the box.
java.lang.IndexOutOfBoundsException - if column<0 || column+width>columns() || row<0 || row+height>rows()
public void setElement(int row,
int column,
boolean value)
column - the index of the column-coordinate.row - the index of the row-coordinate.value - the value of the boolean to be copied into the specified coordinate.
java.lang.IndexOutOfBoundsException - if column<0 || column>=columns() || row<0 || row>=rows()
public void setElement(int row,
int column,
Boolean value)
column - the index of the column-coordinate.row - the index of the row-coordinate.value - the value of the boolean to be copied into the specified coordinate.
java.lang.IndexOutOfBoundsException - if column<0 || column>=columns() || row<0 || row>=rows()public void setAllElements(boolean b)
b - a boolean element
public void replaceBoxWith(int column,
int row,
int width,
int height,
BooleanMatrix source,
int sourceColumn,
int sourceRow)
column - the index of the column-coordinate.row - the index of the row-coordinate.width - the width of the box.height - the height of the box.source - the source matrix to copy from(may be identical to the receiver).sourceColumn - the index of the source column-coordinate.sourceRow - the index of the source row-coordinate.
java.lang.IndexOutOfBoundsException - if column<0 || column+width>columns() || row<0 || row+height>rows()
java.lang.IndexOutOfBoundsException - if sourceColumn<0 || sourceColumn+width>source.columns() || sourceRow<0 || sourceRow+height>source.rows()
public void replaceBoxWith(int column,
int row,
int width,
int height,
boolean value)
column - the index of the column-coordinate.row - the index of the row-coordinate.width - the width of the box.height - the height of the box.value - the value of the boolean to be copied into the booleans of the specified box.
java.lang.IndexOutOfBoundsException - if column<0 || column+width>columns() || row<0 || row+height>rows()public BooleanVector toBooleanVector()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
true if and only if the argument is
not null and is a BooleanMatrix object
that has the same number of columns and rows as the receiver and
that has exactly the same booleans set to true as the receiver.
equals in class java.lang.Objectobj - the object to compare with.
true if the objects are the same;
false otherwise.public java.lang.String toString()
toString in class java.lang.Objectpublic BooleanMatrix clear()
public BooleanMatrix and(BooleanMatrix other)
true if and only if it already had the
value true and the corresponding boolean in the other boolean matrix
argument has the value true.
other - a boolean matrix.
java.lang.IllegalArgumentException - if columns() != other.columns() || rows() != other.rows().public BooleanMatrix andNot(BooleanMatrix other)
other - a boolean matrix with which to mask the receiver.
java.lang.IllegalArgumentException - if columns() != other.columns() || rows() != other.rows().public BooleanMatrix not()
public BooleanMatrix or(BooleanMatrix other)
true if and only if it either already had the
value true or the corresponding boolean in the other boolean matrix
argument has the value true.
other - a boolean matrix.
java.lang.IllegalArgumentException - if columns() != other.columns() || rows() != other.rows().public BooleanMatrix xor(BooleanMatrix other)
true if and only if one of the following statements holds:
true, and the
corresponding boolean in the argument has the value false.
false, and the
corresponding boolean in the argument has the value true.
other - a boolean matrix.
java.lang.IllegalArgumentException - if columns() != other.columns() || rows() != other.rows().public AbelianGroup.Member negate()
negate in interface AbelianGroup.Memberpublic AbelianGroup.Member add(AbelianGroup.Member m)
add in interface AbelianGroup.Memberm - a group member
public BooleanMatrix add(BooleanMatrix m)
m - an boolean matrix
IllegalDimensionException - If the matrices are different sizes.public AbelianGroup.Member subtract(AbelianGroup.Member m)
subtract in interface AbelianGroup.Memberm - a group member
public BooleanMatrix subtract(BooleanMatrix m)
m - a boolean matrix
IllegalDimensionException - If the matrices are different sizes.public Module.Member scalarMultiply(Ring.Member x)
scalarMultiply in interface Module.Memberx - a ring member
public BooleanMatrix scalarMultiply(boolean x)
x - an boolean
public VectorSpace.Member scalarDivide(Field.Member x)
scalarDivide in interface VectorSpace.Memberx - a field member
public BooleanVector multiply(BooleanVector v)
v - an integer vector
IllegalDimensionException - If the matrix and vector are incompatible.public Ring.Member multiply(Ring.Member m)
multiply in interface Ring.Memberm - a ring member
public BooleanMatrix multiply(BooleanMatrix m)
m - an integer matrix
IllegalDimensionException - If the matrices are incompatible.public Matrix transpose()
transpose in interface Matrixpublic BooleanMatrix mapElements(PrimitiveMapping f)
f - a user-defined function
public java.lang.Object clone()
clone in class java.lang.Objectpublic boolean[][] toPrimitiveArray()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||