commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1383052 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java
Date Mon, 10 Sep 2012 19:05:54 GMT
Author: celestin
Date: Mon Sep 10 19:05:54 2012
New Revision: 1383052

URL: http://svn.apache.org/viewvc?rev=1383052&view=rev
Log:
MATH-854: fill the "throws" clause of ArrayFieldVector.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java?rev=1383052&r1=1383051&r2=1383052&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java
Mon Sep 10 19:05:54 2012
@@ -47,7 +47,7 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Build a 0-length vector.
-     * Zero-length vectors may be used to initialized construction of vectors
+     * Zero-length vectors may be used to initialize construction of vectors
      * by data gathering. We start with zero-length and use either the {@link
      * #ArrayFieldVector(ArrayFieldVector, ArrayFieldVector)} constructor
      * or one of the {@code append} methods ({@link #add(FieldVector)} or
@@ -94,7 +94,8 @@ public class ArrayFieldVector<T extends 
      * @throws ZeroException if {@code d} is empty.
      * @see #ArrayFieldVector(Field, FieldElement[])
      */
-    public ArrayFieldVector(T[] d) {
+    public ArrayFieldVector(T[] d)
+            throws NullArgumentException, ZeroException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -114,7 +115,8 @@ public class ArrayFieldVector<T extends 
      * @throws NullArgumentException if {@code d} is {@code null}.
      * @see #ArrayFieldVector(FieldElement[])
      */
-    public ArrayFieldVector(Field<T> field, T[] d) {
+    public ArrayFieldVector(Field<T> field, T[] d)
+            throws NullArgumentException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -143,7 +145,8 @@ public class ArrayFieldVector<T extends 
      * @see #ArrayFieldVector(FieldElement[])
      * @see #ArrayFieldVector(Field, FieldElement[], boolean)
      */
-    public ArrayFieldVector(T[] d, boolean copyArray) {
+    public ArrayFieldVector(T[] d, boolean copyArray)
+            throws NullArgumentException, ZeroException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -151,7 +154,7 @@ public class ArrayFieldVector<T extends 
             throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
         }
         field = d[0].getField();
-        data = copyArray ? d.clone() :  d;
+        data = copyArray ? d.clone() : d;
     }
 
     /**
@@ -169,7 +172,8 @@ public class ArrayFieldVector<T extends 
      * @throws NullArgumentException if {@code d} is {@code null}.
      * @see #ArrayFieldVector(FieldElement[], boolean)
      */
-    public ArrayFieldVector(Field<T> field, T[] d, boolean copyArray) {
+    public ArrayFieldVector(Field<T> field, T[] d, boolean copyArray)
+            throws NullArgumentException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -187,7 +191,8 @@ public class ArrayFieldVector<T extends 
      * @throws NumberIsTooLargeException if the size of {@code d} is less
      * than {@code pos + size}.
      */
-    public ArrayFieldVector(T[] d, int pos, int size) {
+    public ArrayFieldVector(T[] d, int pos, int size)
+            throws NullArgumentException, NumberIsTooLargeException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -210,7 +215,8 @@ public class ArrayFieldVector<T extends 
      * @throws NumberIsTooLargeException if the size of {@code d} is less
      * than {@code pos + size}.
      */
-    public ArrayFieldVector(Field<T> field, T[] d, int pos, int size) {
+    public ArrayFieldVector(Field<T> field, T[] d, int pos, int size)
+            throws NullArgumentException, NumberIsTooLargeException {
         if (d == null) {
             throw new NullArgumentException();
         }
@@ -228,7 +234,8 @@ public class ArrayFieldVector<T extends 
      * @param v Vector to copy.
      * @throws NullArgumentException if {@code v} is {@code null}.
      */
-    public ArrayFieldVector(FieldVector<T> v) {
+    public ArrayFieldVector(FieldVector<T> v)
+            throws NullArgumentException {
         if (v == null) {
             throw new NullArgumentException();
         }
@@ -245,7 +252,8 @@ public class ArrayFieldVector<T extends 
      * @param v Vector to copy.
      * @throws NullArgumentException if {@code v} is {@code null}.
      */
-    public ArrayFieldVector(ArrayFieldVector<T> v) {
+    public ArrayFieldVector(ArrayFieldVector<T> v)
+            throws NullArgumentException {
         if (v == null) {
             throw new NullArgumentException();
         }
@@ -261,7 +269,8 @@ public class ArrayFieldVector<T extends 
      * a shallow copy
      * @throws NullArgumentException if {@code v} is {@code null}.
      */
-    public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep) {
+    public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep)
+            throws NullArgumentException {
         if (v == null) {
             throw new NullArgumentException();
         }
@@ -277,9 +286,9 @@ public class ArrayFieldVector<T extends 
      * @throws NullArgumentException if {@code v1} or {@code v2} is
      * {@code null}.
      */
-    public ArrayFieldVector(ArrayFieldVector<T> v1, ArrayFieldVector<T> v2) {
-        if (v1 == null ||
-            v2 == null) {
+    public ArrayFieldVector(ArrayFieldVector<T> v1, ArrayFieldVector<T> v2)
+            throws NullArgumentException {
+        if (v1 == null || v2 == null) {
             throw new NullArgumentException();
         }
         field = v1.getField();
@@ -296,9 +305,9 @@ public class ArrayFieldVector<T extends 
      * @throws NullArgumentException if {@code v1} or {@code v2} is
      * {@code null}.
      */
-    public ArrayFieldVector(ArrayFieldVector<T> v1, T[] v2) {
-        if (v1 == null ||
-            v2 == null) {
+    public ArrayFieldVector(ArrayFieldVector<T> v1, T[] v2)
+            throws NullArgumentException {
+        if (v1 == null || v2 == null) {
             throw new NullArgumentException();
         }
         field = v1.getField();
@@ -315,9 +324,9 @@ public class ArrayFieldVector<T extends 
      * @throws NullArgumentException if {@code v1} or {@code v2} is
      * {@code null}.
      */
-    public ArrayFieldVector(T[] v1, ArrayFieldVector<T> v2) {
-        if (v1 == null ||
-            v2 == null) {
+    public ArrayFieldVector(T[] v1, ArrayFieldVector<T> v2)
+            throws NullArgumentException {
+        if (v1 == null || v2 == null) {
             throw new NullArgumentException();
         }
         field = v2.getField();
@@ -341,9 +350,9 @@ public class ArrayFieldVector<T extends 
      * @throws ZeroException if both arrays are empty.
      * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
      */
-    public ArrayFieldVector(T[] v1, T[] v2) {
-        if (v1 == null ||
-            v2 == null) {
+    public ArrayFieldVector(T[] v1, T[] v2)
+            throws NullArgumentException, ZeroException {
+        if (v1 == null || v2 == null) {
             throw new NullArgumentException();
         }
         if (v1.length + v2.length == 0) {
@@ -366,7 +375,11 @@ public class ArrayFieldVector<T extends 
      * @throws ZeroException if both arrays are empty.
      * @see #ArrayFieldVector(FieldElement[], FieldElement[])
      */
-    public ArrayFieldVector(Field<T> field, T[] v1, T[] v2) {
+    public ArrayFieldVector(Field<T> field, T[] v1, T[] v2)
+            throws NullArgumentException, ZeroException {
+        if (v1 == null || v2 == null) {
+            throw new NullArgumentException();
+        }
         if (v1.length + v2.length == 0) {
             throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
         }
@@ -398,7 +411,8 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> add(FieldVector<T> v) {
+    public FieldVector<T> add(FieldVector<T> v)
+        throws DimensionMismatchException {
         try {
             return add((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -412,12 +426,14 @@ public class ArrayFieldVector<T extends 
     }
 
     /**
-     * Compute the sum of this and v.
+     * Compute the sum of {@code this} and {@code v}.
      * @param v vector to be added
-     * @return this + v
-     * @throws IllegalArgumentException if v is not the same size as this
+     * @return {@code this + v}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public ArrayFieldVector<T> add(ArrayFieldVector<T> v) {
+    public ArrayFieldVector<T> add(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.data.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -427,7 +443,8 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> subtract(FieldVector<T> v) {
+    public FieldVector<T> subtract(FieldVector<T> v)
+        throws DimensionMismatchException {
         try {
             return subtract((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -441,12 +458,14 @@ public class ArrayFieldVector<T extends 
     }
 
     /**
-     * Compute this minus v.
+     * Compute {@code this} minus {@code v}.
      * @param v vector to be subtracted
-     * @return this + v
-     * @throws IllegalArgumentException if v is not the same size as this
+     * @return {@code this - v}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v) {
+    public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.data.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -543,7 +562,8 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeMultiply(FieldVector<T> v) {
+    public FieldVector<T> ebeMultiply(FieldVector<T> v)
+        throws DimensionMismatchException {
         try {
             return ebeMultiply((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -559,10 +579,12 @@ public class ArrayFieldVector<T extends 
     /**
      * Element-by-element multiplication.
      * @param v vector by which instance elements must be multiplied
-     * @return a vector containing this[i] * v[i] for all i
-     * @exception IllegalArgumentException if v is not the same size as this
+     * @return a vector containing {@code this[i] * v[i]} for all {@code i}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v) {
+    public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.data.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -572,7 +594,8 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeDivide(FieldVector<T> v) {
+    public FieldVector<T> ebeDivide(FieldVector<T> v)
+        throws DimensionMismatchException {
         try {
             return ebeDivide((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -588,10 +611,12 @@ public class ArrayFieldVector<T extends 
     /**
      * Element-by-element division.
      * @param v vector by which instance elements must be divided
-     * @return a vector containing this[i] / v[i] for all i
-     * @throws IllegalArgumentException if v is not the same size as this
+     * @return a vector containing {@code this[i] / v[i]} for all {@code i}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v) {
+    public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.data.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -615,7 +640,8 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public T dotProduct(FieldVector<T> v) {
+    public T dotProduct(FieldVector<T> v)
+        throws DimensionMismatchException {
         try {
             return dotProduct((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -631,10 +657,12 @@ public class ArrayFieldVector<T extends 
     /**
      * Compute the dot product.
      * @param v vector with which dot product should be computed
-     * @return the scalar dot product between instance and v
-     * @exception IllegalArgumentException if v is not the same size as this
+     * @return the scalar dot product of {@code this} and {@code v}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public T dotProduct(ArrayFieldVector<T> v) {
+    public T dotProduct(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.data.length);
         T dot = field.getZero();
         for (int i = 0; i < data.length; i++) {
@@ -644,16 +672,19 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> projection(FieldVector<T> v) {
+    public FieldVector<T> projection(FieldVector<T> v)
+        throws DimensionMismatchException {
         return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
     }
 
-   /** Find the orthogonal projection of this vector onto another vector.
-     * @param v vector onto which instance must be projected
-     * @return projection of the instance onto v
-     * @throws IllegalArgumentException if v is not the same size as this
+    /** Find the orthogonal projection of this vector onto another vector.
+     * @param v vector onto which {@code this} must be projected
+     * @return projection of {@code this} onto {@code v}
+     * @throws DimensionMismatchException if {@code v} is not the same size as
+     * {@code this}
      */
-    public ArrayFieldVector<T> projection(ArrayFieldVector<T> v) {
+    public ArrayFieldVector<T> projection(ArrayFieldVector<T> v)
+        throws DimensionMismatchException {
         return (ArrayFieldVector<T>) v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
     }
 
@@ -677,8 +708,7 @@ public class ArrayFieldVector<T extends 
     /**
      * Compute the outer product.
      * @param v vector with which outer product should be computed
-     * @return the square matrix outer product between instance and v
-     * @exception IllegalArgumentException if v is not the same size as this
+     * @return the matrix outer product between instance and v
      */
     public FieldMatrix<T> outerProduct(ArrayFieldVector<T> v) {
         final int m = data.length;
@@ -770,10 +800,9 @@ public class ArrayFieldVector<T extends 
      *
      * @param index index of first element to be set.
      * @param v vector containing the values to set.
-     * @throws OutOfRangeException if the index is
-     * inconsistent with vector size
+     * @throws OutOfRangeException if the index is invalid.
      */
-    public void set(int index, ArrayFieldVector<T> v) {
+    public void set(int index, ArrayFieldVector<T> v) throws OutOfRangeException {
         try {
             System.arraycopy(v.data, 0, data, index, v.data.length);
         } catch (IndexOutOfBoundsException e) {
@@ -795,10 +824,11 @@ public class ArrayFieldVector<T extends 
     /**
      * Check if instance and specified vectors have the same dimension.
      * @param v vector to compare instance with
-     * @exception IllegalArgumentException if the vectors do not
-     * have the same dimension
+     * @exception DimensionMismatchException if the vectors do not
+     * have the same dimensions
      */
-    protected void checkVectorDimensions(FieldVector<T> v) {
+    protected void checkVectorDimensions(FieldVector<T> v)
+        throws DimensionMismatchException {
         checkVectorDimensions(v.getDimension());
     }
 
@@ -806,10 +836,11 @@ public class ArrayFieldVector<T extends 
      * Check if instance dimension is equal to some expected value.
      *
      * @param n Expected dimension.
-     * @throws OutOfRangeException if the dimension is
-     * inconsistent with this vector size.
+     * @throws DimensionMismatchException if the dimension is not equal to the
+     * size of {@code this} vector.
      */
-    protected void checkVectorDimensions(int n) {
+    protected void checkVectorDimensions(int n)
+        throws DimensionMismatchException {
         if (data.length != n) {
             throw new DimensionMismatchException(data.length, n);
         }
@@ -870,7 +901,7 @@ public class ArrayFieldVector<T extends 
      * @param index Index to check.
      * @exception OutOfRangeException if the index is not valid.
      */
-    private void checkIndex(final int index) {
+    private void checkIndex(final int index) throws OutOfRangeException {
         if (index < 0 || index >= getDimension()) {
             throw new OutOfRangeException(LocalizedFormats.INDEX,
                                           index, 0, getDimension() - 1);



Mime
View raw message