MATH-854: populated throws clause of Array2DRowFieldMatrix.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1392748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-10-02 05:35:59 +00:00
parent 72051d7f6d
commit bb0827cc81
2 changed files with 68 additions and 43 deletions

View File

@ -175,7 +175,9 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>>
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension); public abstract FieldMatrix<T> createMatrix(final int rowDimension,
final int columnDimension)
throws NotStrictlyPositiveException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract FieldMatrix<T> copy(); public abstract FieldMatrix<T> copy();
@ -656,16 +658,16 @@ public abstract class AbstractFieldMatrix<T extends FieldElement<T>>
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract T getEntry(int row, int column); public abstract T getEntry(int row, int column) throws OutOfRangeException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract void setEntry(int row, int column, T value); public abstract void setEntry(int row, int column, T value) throws OutOfRangeException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract void addToEntry(int row, int column, T increment); public abstract void addToEntry(int row, int column, T increment) throws OutOfRangeException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public abstract void multiplyEntry(int row, int column, T factor); public abstract void multiplyEntry(int row, int column, T factor) throws OutOfRangeException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public FieldMatrix<T> transpose() { public FieldMatrix<T> transpose() {

View File

@ -24,7 +24,10 @@ import org.apache.commons.math3.FieldElement;
import org.apache.commons.math3.exception.NoDataException; import org.apache.commons.math3.exception.NoDataException;
import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.MathIllegalStateException; import org.apache.commons.math3.exception.MathIllegalStateException;
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.exception.OutOfRangeException;
import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.exception.util.LocalizedFormats;
import org.apache.commons.math3.util.MathUtils; import org.apache.commons.math3.util.MathUtils;
@ -61,12 +64,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* @param field Field to which the elements belong. * @param field Field to which the elements belong.
* @param rowDimension Number of rows in the new matrix. * @param rowDimension Number of rows in the new matrix.
* @param columnDimension Number of columns in the new matrix. * @param columnDimension Number of columns in the new matrix.
* @throws org.apache.commons.math3.exception.NotStrictlyPositiveException * @throws NotStrictlyPositiveException if row or column dimension is not positive.
* if row or column dimension is not positive.
*/ */
public Array2DRowFieldMatrix(final Field<T> field, public Array2DRowFieldMatrix(final Field<T> field, final int rowDimension,
final int rowDimension, final int columnDimension)
final int columnDimension) { throws NotStrictlyPositiveException {
super(field, rowDimension, columnDimension); super(field, rowDimension, columnDimension);
data = buildArray(field, rowDimension, columnDimension); data = buildArray(field, rowDimension, columnDimension);
} }
@ -80,12 +82,13 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* *
* @param d Data for the new matrix. * @param d Data for the new matrix.
* @throws DimensionMismatchException if {@code d} is not rectangular. * @throws DimensionMismatchException if {@code d} is not rectangular.
* @throws org.apache.commons.math3.exception.NullArgumentException if * @throws NullArgumentException if {@code d} is {@code null}.
* {@code d} is {@code null}.
* @throws NoDataException if there are not at least one row and one column. * @throws NoDataException if there are not at least one row and one column.
* @see #Array2DRowFieldMatrix(FieldElement[][], boolean) * @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
*/ */
public Array2DRowFieldMatrix(final T[][] d) { public Array2DRowFieldMatrix(final T[][] d)
throws DimensionMismatchException, NullArgumentException,
NoDataException {
this(extractField(d), d); this(extractField(d), d);
} }
@ -99,12 +102,13 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* @param field Field to which the elements belong. * @param field Field to which the elements belong.
* @param d Data for the new matrix. * @param d Data for the new matrix.
* @throws DimensionMismatchException if {@code d} is not rectangular. * @throws DimensionMismatchException if {@code d} is not rectangular.
* @throws org.apache.commons.math3.exception.NullArgumentException if * @throws NullArgumentException if {@code d} is {@code null}.
* {@code d} is {@code null}.
* @throws NoDataException if there are not at least one row and one column. * @throws NoDataException if there are not at least one row and one column.
* @see #Array2DRowFieldMatrix(FieldElement[][], boolean) * @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
*/ */
public Array2DRowFieldMatrix(final Field<T> field, final T[][] d) { public Array2DRowFieldMatrix(final Field<T> field, final T[][] d)
throws DimensionMismatchException, NullArgumentException,
NoDataException {
super(field); super(field);
copyIn(d); copyIn(d);
} }
@ -121,11 +125,12 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* @param copyArray Whether to copy or reference the input array. * @param copyArray Whether to copy or reference the input array.
* @throws DimensionMismatchException if {@code d} is not rectangular. * @throws DimensionMismatchException if {@code d} is not rectangular.
* @throws NoDataException if there are not at least one row and one column. * @throws NoDataException if there are not at least one row and one column.
* @throws org.apache.commons.math3.exception.NullArgumentException * @throws NullArgumentException if {@code d} is {@code null}.
* if {@code d} is {@code null}.
* @see #Array2DRowFieldMatrix(FieldElement[][]) * @see #Array2DRowFieldMatrix(FieldElement[][])
*/ */
public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray) { public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray)
throws DimensionMismatchException, NoDataException,
NullArgumentException {
this(extractField(d), d, copyArray); this(extractField(d), d, copyArray);
} }
@ -175,8 +180,9 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* The input array is copied. * The input array is copied.
* *
* @param v Column vector holding data for new matrix. * @param v Column vector holding data for new matrix.
* @throws NoDataException if v is empty
*/ */
public Array2DRowFieldMatrix(final T[] v) { public Array2DRowFieldMatrix(final T[] v) throws NoDataException {
this(extractField(v), v); this(extractField(v), v);
} }
@ -199,7 +205,9 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) { public FieldMatrix<T> createMatrix(final int rowDimension,
final int columnDimension)
throws NotStrictlyPositiveException {
return new Array2DRowFieldMatrix<T>(getField(), rowDimension, columnDimension); return new Array2DRowFieldMatrix<T>(getField(), rowDimension, columnDimension);
} }
@ -214,10 +222,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* *
* @param m Matrix to be added. * @param m Matrix to be added.
* @return {@code this} + m. * @return {@code this} + m.
* @throws MatrixDimensionMismatchException * @throws MatrixDimensionMismatchException if {@code m} is not the same
* if {@code m} is not the same size as this matrix. * size as this matrix.
*/ */
public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m) { public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m)
throws MatrixDimensionMismatchException {
// safety check // safety check
checkAdditionCompatible(m); checkAdditionCompatible(m);
@ -241,10 +250,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* *
* @param m Matrix to be subtracted. * @param m Matrix to be subtracted.
* @return {@code this} + m. * @return {@code this} + m.
* @throws MatrixDimensionMismatchException * @throws MatrixDimensionMismatchException if {@code m} is not the same
* if {@code m} is not the same size as this matrix. * size as this matrix.
*/ */
public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m) { public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m)
throws MatrixDimensionMismatchException {
// safety check // safety check
checkSubtractionCompatible(m); checkSubtractionCompatible(m);
@ -272,7 +282,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* @throws DimensionMismatchException if the number of columns of this * @throws DimensionMismatchException if the number of columns of this
* matrix is not equal to the number of rows of {@code m}. * matrix is not equal to the number of rows of {@code m}.
*/ */
public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m) { public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m)
throws DimensionMismatchException {
// safety check // safety check
checkMultiplicationCompatible(m); checkMultiplicationCompatible(m);
@ -314,7 +325,10 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) { public void setSubMatrix(final T[][] subMatrix, final int row,
final int column)
throws OutOfRangeException, NullArgumentException, NoDataException,
DimensionMismatchException {
if (data == null) { if (data == null) {
if (row > 0) { if (row > 0) {
throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row); throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
@ -346,7 +360,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public T getEntry(final int row, final int column) { public T getEntry(final int row, final int column)
throws OutOfRangeException {
checkRowIndex(row); checkRowIndex(row);
checkColumnIndex(column); checkColumnIndex(column);
@ -355,7 +370,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setEntry(final int row, final int column, final T value) { public void setEntry(final int row, final int column, final T value)
throws OutOfRangeException {
checkRowIndex(row); checkRowIndex(row);
checkColumnIndex(column); checkColumnIndex(column);
@ -364,7 +380,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void addToEntry(final int row, final int column, final T increment) { public void addToEntry(final int row, final int column, final T increment)
throws OutOfRangeException {
checkRowIndex(row); checkRowIndex(row);
checkColumnIndex(column); checkColumnIndex(column);
@ -373,7 +390,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void multiplyEntry(final int row, final int column, final T factor) { public void multiplyEntry(final int row, final int column, final T factor)
throws OutOfRangeException {
checkRowIndex(row); checkRowIndex(row);
checkColumnIndex(column); checkColumnIndex(column);
@ -394,7 +412,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public T[] operate(final T[] v) { public T[] operate(final T[] v) throws DimensionMismatchException {
final int nRows = this.getRowDimension(); final int nRows = this.getRowDimension();
final int nCols = this.getColumnDimension(); final int nCols = this.getColumnDimension();
if (v.length != nCols) { if (v.length != nCols) {
@ -414,7 +432,7 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public T[] preMultiply(final T[] v) { public T[] preMultiply(final T[] v) throws DimensionMismatchException {
final int nRows = getRowDimension(); final int nRows = getRowDimension();
final int nCols = getColumnDimension(); final int nCols = getColumnDimension();
if (v.length != nRows) { if (v.length != nRows) {
@ -467,7 +485,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
@Override @Override
public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor, public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) { final int startColumn, final int endColumn)
throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -484,7 +503,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
@Override @Override
public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor, public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) { final int startColumn, final int endColumn)
throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -530,8 +550,9 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
@Override @Override
public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor, public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) { final int startColumn, final int endColumn)
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
for (int j = startColumn; j <= endColumn; ++j) { for (int j = startColumn; j <= endColumn; ++j) {
@ -547,7 +568,8 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
@Override @Override
public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor, public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor,
final int startRow, final int endRow, final int startRow, final int endRow,
final int startColumn, final int endColumn) { final int startColumn, final int endColumn)
throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
visitor.start(getRowDimension(), getColumnDimension(), visitor.start(getRowDimension(), getColumnDimension(),
startRow, endRow, startColumn, endColumn); startRow, endRow, startColumn, endColumn);
@ -580,10 +602,11 @@ public class Array2DRowFieldMatrix<T extends FieldElement<T>>
* @param in Data to copy. * @param in Data to copy.
* @throws NoDataException if the input array is empty. * @throws NoDataException if the input array is empty.
* @throws DimensionMismatchException if the input array is not rectangular. * @throws DimensionMismatchException if the input array is not rectangular.
* @throws org.apache.commons.math3.exception.NullArgumentException if * @throws NullArgumentException if the input array is {@code null}.
* the input array is {@code null}.
*/ */
private void copyIn(final T[][] in) { private void copyIn(final T[][] in)
throws NullArgumentException, NoDataException,
DimensionMismatchException {
setSubMatrix(in, 0, 0); setSubMatrix(in, 0, 0);
} }
} }