From 8469bc496c0f6f629b0f6406e11bc8ad5a93b0b4 Mon Sep 17 00:00:00 2001 From: Sebastien Brisard Date: Thu, 13 Sep 2012 06:11:05 +0000 Subject: [PATCH] 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 --- .../math3/linear/ArrayFieldVector.java | 162 +++++++++++++----- 1 file changed, 122 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java b/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java index 28b9d738a..9557be77b 100644 --- a/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java +++ b/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java @@ -97,7 +97,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[]) */ public ArrayFieldVector(T[] d) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (d == null) { throw new NullArgumentException(); } @@ -118,7 +118,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[]) */ public ArrayFieldVector(Field field, T[] d) - throws NullArgumentException { + throws NullArgumentException { if (d == null) { throw new NullArgumentException(); } @@ -148,7 +148,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[], boolean) */ public ArrayFieldVector(T[] d, boolean copyArray) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (d == null) { throw new NullArgumentException(); } @@ -175,7 +175,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[], boolean) */ public ArrayFieldVector(Field field, T[] d, boolean copyArray) - throws NullArgumentException { + throws NullArgumentException { if (d == null) { throw new NullArgumentException(); } @@ -194,7 +194,7 @@ public class ArrayFieldVector> implements FieldVector< * than {@code pos + size}. */ public ArrayFieldVector(T[] d, int pos, int size) - throws NullArgumentException, NumberIsTooLargeException { + throws NullArgumentException, NumberIsTooLargeException { if (d == null) { throw new NullArgumentException(); } @@ -218,7 +218,7 @@ public class ArrayFieldVector> implements FieldVector< * than {@code pos + size}. */ public ArrayFieldVector(Field field, T[] d, int pos, int size) - throws NullArgumentException, NumberIsTooLargeException { + throws NullArgumentException, NumberIsTooLargeException { if (d == null) { throw new NullArgumentException(); } @@ -237,7 +237,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(FieldVector v) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -255,7 +255,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector v) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -272,7 +272,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector v, boolean deep) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -289,7 +289,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(ArrayFieldVector v1, ArrayFieldVector v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -308,7 +308,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(ArrayFieldVector v1, T[] v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -327,7 +327,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(T[] v1, ArrayFieldVector v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -353,7 +353,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[]) */ public ArrayFieldVector(T[] v1, T[] v2) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -378,7 +378,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[], FieldElement[]) */ public ArrayFieldVector(Field field, T[] v1, T[] v2) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -412,7 +412,12 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(this, true); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws DimensionMismatchException if {@code v} is not the same size as + * {@code this}. + */ public FieldVector add(FieldVector v) throws DimensionMismatchException { try { @@ -444,7 +449,12 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws DimensionMismatchException if {@code v} is not the same size as + * {@code this}. + */ public FieldVector subtract(FieldVector v) throws DimensionMismatchException { try { @@ -476,8 +486,12 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ - public FieldVector mapAdd(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapAdd(T d) throws NullArgumentException { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(d); @@ -485,16 +499,24 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ - public FieldVector mapAddToSelf(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapAddToSelf(T d) throws NullArgumentException { for (int i = 0; i < data.length; i++) { data[i] = data[i].add(d); } return this; } - /** {@inheritDoc} */ - public FieldVector mapSubtract(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapSubtract(T d) throws NullArgumentException { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(d); @@ -502,16 +524,24 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ - public FieldVector mapSubtractToSelf(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapSubtractToSelf(T d) throws NullArgumentException { for (int i = 0; i < data.length; i++) { data[i] = data[i].subtract(d); } return this; } - /** {@inheritDoc} */ - public FieldVector mapMultiply(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapMultiply(T d) throws NullArgumentException { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].multiply(d); @@ -519,15 +549,24 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ - public FieldVector mapMultiplyToSelf(T d) { + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + */ + public FieldVector mapMultiplyToSelf(T d) throws NullArgumentException { for (int i = 0; i < data.length; i++) { data[i] = data[i].multiply(d); } return this; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + * @throws MathArithmeticException if {@code d} is zero. + */ public FieldVector mapDivide(T d) throws NullArgumentException, MathArithmeticException { if (d == null) { @@ -540,7 +579,12 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws NullArgumentException if {@code d} is {@code null}. + * @throws MathArithmeticException if {@code d} is zero. + */ public FieldVector mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException { if (d == null) { @@ -552,7 +596,11 @@ public class ArrayFieldVector> implements FieldVector< return this; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws MathArithmeticException if {@code d} is zero. + */ public FieldVector mapInv() throws MathArithmeticException { T[] out = buildArray(data.length); final T one = field.getOne(); @@ -566,7 +614,11 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws MathArithmeticException if {@code d} is zero. + */ public FieldVector mapInvToSelf() throws MathArithmeticException { final T one = field.getOne(); for (int i = 0; i < data.length; i++) { @@ -579,7 +631,12 @@ public class ArrayFieldVector> implements FieldVector< return this; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws DimensionMismatchException if {@code v} is not the same size as + * {@code this}. + */ public FieldVector ebeMultiply(FieldVector v) throws DimensionMismatchException { try { @@ -611,7 +668,13 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(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 ebeDivide(FieldVector v) throws DimensionMismatchException, MathArithmeticException { try { @@ -666,9 +729,13 @@ public class ArrayFieldVector> implements FieldVector< return data; } - /** {@inheritDoc} */ - public T dotProduct(FieldVector v) - throws DimensionMismatchException { + /** + * {@inheritDoc} + * + * @throws DimensionMismatchException if {@code v} is not the same size as + * {@code this}. + */ + public T dotProduct(FieldVector v) throws DimensionMismatchException { try { return dotProduct((ArrayFieldVector) v); } catch (ClassCastException cce) { @@ -698,7 +765,13 @@ public class ArrayFieldVector> implements FieldVector< 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 projection(FieldVector v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); @@ -786,7 +859,12 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(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 getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { @@ -811,7 +889,11 @@ public class ArrayFieldVector> implements FieldVector< } } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + * + * @throws OutOfRangeException if the index is not valid. + */ public void setSubVector(int index, FieldVector v) throws OutOfRangeException { try { try {