MATH-854: document all exceptions in ArrayFieldVector.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1384212 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-09-13 06:11:05 +00:00
parent 10af7e2b2f
commit 8469bc496c
1 changed files with 122 additions and 40 deletions

View File

@ -412,7 +412,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(this, true); return new ArrayFieldVector<T>(this, true);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
*/
public FieldVector<T> add(FieldVector<T> v) public FieldVector<T> add(FieldVector<T> v)
throws DimensionMismatchException { throws DimensionMismatchException {
try { try {
@ -444,7 +449,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
*/
public FieldVector<T> subtract(FieldVector<T> v) public FieldVector<T> subtract(FieldVector<T> v)
throws DimensionMismatchException { throws DimensionMismatchException {
try { try {
@ -476,8 +486,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapAdd(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapAdd(T d) throws NullArgumentException {
T[] out = buildArray(data.length); T[] out = buildArray(data.length);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
out[i] = data[i].add(d); out[i] = data[i].add(d);
@ -485,16 +499,24 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapAddToSelf(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapAddToSelf(T d) throws NullArgumentException {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = data[i].add(d); data[i] = data[i].add(d);
} }
return this; return this;
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapSubtract(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapSubtract(T d) throws NullArgumentException {
T[] out = buildArray(data.length); T[] out = buildArray(data.length);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
out[i] = data[i].subtract(d); out[i] = data[i].subtract(d);
@ -502,16 +524,24 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapSubtractToSelf(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = data[i].subtract(d); data[i] = data[i].subtract(d);
} }
return this; return this;
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapMultiply(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapMultiply(T d) throws NullArgumentException {
T[] out = buildArray(data.length); T[] out = buildArray(data.length);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
out[i] = data[i].multiply(d); out[i] = data[i].multiply(d);
@ -519,15 +549,24 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
public FieldVector<T> mapMultiplyToSelf(T d) { * {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
*/
public FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = data[i].multiply(d); data[i] = data[i].multiply(d);
} }
return this; return this;
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
* @throws MathArithmeticException if {@code d} is zero.
*/
public FieldVector<T> mapDivide(T d) public FieldVector<T> mapDivide(T d)
throws NullArgumentException, MathArithmeticException { throws NullArgumentException, MathArithmeticException {
if (d == null) { if (d == null) {
@ -540,7 +579,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws NullArgumentException if {@code d} is {@code null}.
* @throws MathArithmeticException if {@code d} is zero.
*/
public FieldVector<T> mapDivideToSelf(T d) public FieldVector<T> mapDivideToSelf(T d)
throws NullArgumentException, MathArithmeticException { throws NullArgumentException, MathArithmeticException {
if (d == null) { if (d == null) {
@ -552,7 +596,11 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return this; return this;
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws MathArithmeticException if {@code d} is zero.
*/
public FieldVector<T> mapInv() throws MathArithmeticException { public FieldVector<T> mapInv() throws MathArithmeticException {
T[] out = buildArray(data.length); T[] out = buildArray(data.length);
final T one = field.getOne(); final T one = field.getOne();
@ -566,7 +614,11 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws MathArithmeticException if {@code d} is zero.
*/
public FieldVector<T> mapInvToSelf() throws MathArithmeticException { public FieldVector<T> mapInvToSelf() throws MathArithmeticException {
final T one = field.getOne(); final T one = field.getOne();
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@ -579,7 +631,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return this; return this;
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
*/
public FieldVector<T> ebeMultiply(FieldVector<T> v) public FieldVector<T> ebeMultiply(FieldVector<T> v)
throws DimensionMismatchException { throws DimensionMismatchException {
try { try {
@ -611,7 +668,13 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
* @throws MathArithmeticException if one entry of {@code v} is zero.
*/
public FieldVector<T> ebeDivide(FieldVector<T> v) public FieldVector<T> ebeDivide(FieldVector<T> v)
throws DimensionMismatchException, MathArithmeticException { throws DimensionMismatchException, MathArithmeticException {
try { try {
@ -666,9 +729,13 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return data; return data;
} }
/** {@inheritDoc} */ /**
public T dotProduct(FieldVector<T> v) * {@inheritDoc}
throws DimensionMismatchException { *
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
*/
public T dotProduct(FieldVector<T> v) throws DimensionMismatchException {
try { try {
return dotProduct((ArrayFieldVector<T>) v); return dotProduct((ArrayFieldVector<T>) v);
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
@ -698,7 +765,13 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return dot; return dot;
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this}.
* @throws MathArithmeticException if {@code v} is the null vector.
*/
public FieldVector<T> projection(FieldVector<T> v) public FieldVector<T> projection(FieldVector<T> v)
throws DimensionMismatchException, MathArithmeticException { throws DimensionMismatchException, MathArithmeticException {
return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
@ -786,7 +859,12 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
return new ArrayFieldVector<T>(field, out, false); return new ArrayFieldVector<T>(field, out, false);
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws OutOfRangeException if the index is not valid.
* @throws NotPositiveException if the number of elements is not positive.
*/
public FieldVector<T> getSubVector(int index, int n) public FieldVector<T> getSubVector(int index, int n)
throws OutOfRangeException, NotPositiveException { throws OutOfRangeException, NotPositiveException {
if (n < 0) { if (n < 0) {
@ -811,7 +889,11 @@ public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<
} }
} }
/** {@inheritDoc} */ /**
* {@inheritDoc}
*
* @throws OutOfRangeException if the index is not valid.
*/
public void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException { public void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException {
try { try {
try { try {