You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2010/10/27 15:16:58 UTC

svn commit: r1027952 [1/5] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ main/java/org/apache/commons/math/linear/ main/resources/META-INF/localization/ test/java/org...

Author: erans
Date: Wed Oct 27 13:16:57 2010
New Revision: 1027952

URL: http://svn.apache.org/viewvc?rev=1027952&view=rev
Log:
MATH-425
Deleted deprecated classes in package "linear".
Removed redundant methods in "Array2DRowRealMatrix".
Removed usage of "MatrixIndexException" (class is now deprecated).
Javadoc clean up.

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java   (with props)
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BigMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BigMatrixImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealMatrixImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BigMatrixImplTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealMatrixImplTest.java
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/FieldVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixIndexException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/MatrixUtils.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldMatrix.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/SparseFieldVector.java
    commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayFieldVectorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1027952&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Wed Oct 27 13:16:57 2010
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.exception;
+
+import java.util.Locale;
+
+import org.apache.commons.math.exception.util.ArgUtils;
+import org.apache.commons.math.exception.util.MessageFactory;
+import org.apache.commons.math.exception.util.Localizable;
+import org.apache.commons.math.exception.util.LocalizedFormats;
+
+/**
+ * Base class for arithmetic exceptions.
+ * It is used for all the exceptions that share the semantics of the standard
+ * {@link ArithmeticException}, but must also provide a localized
+ * message.
+ *
+ * @since 3.0
+ * @version $Revision$ $Date$
+ */
+public class MathArithmeticException extends ArithmeticException {
+
+    /** Serializable version Id. */
+    private static final long serialVersionUID = -6024911025449780478L;
+
+    /**
+     * Pattern used to build the message (specific context).
+     */
+    private final Localizable specific;
+    /**
+     * Arguments used to build the message.
+     */
+    private final Object[] arguments;
+
+    /**
+     * @param args Arguments.
+     */
+    public MathArithmeticException(Object ... args) {
+        this(null, args);
+    }
+    /**
+     * @param specific Message pattern providing the specific context of
+     * the error.
+     * @param args Arguments.
+     */
+    public MathArithmeticException(Localizable specific,
+                                   Object ... args) {
+        this.specific = specific;
+        arguments = ArgUtils.flatten(args);
+    }
+
+    /**
+     * Get the message in a specified locale.
+     *
+     * @param locale Locale in which the message should be translated.
+     *
+     * @return the localized message.
+     */
+    public String getMessage(final Locale locale) {
+        return MessageFactory.buildMessage(locale,
+                                           specific,
+                                           LocalizedFormats.UNSUPPORTED_OPERATION,
+                                           arguments);
+    }
+
+   /** {@inheritDoc} */
+    @Override
+    public String getMessage() {
+        return getMessage(Locale.US);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLocalizedMessage() {
+        return getMessage(Locale.getDefault());
+    }
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Wed Oct 27 13:16:57 2010
@@ -112,11 +112,12 @@ public enum LocalizedFormats implements 
     INDEX_LARGER_THAN_MAX("the index specified: {0} is larger than the current maximal index {1}"),
     INDEX_NOT_POSITIVE("index ({0}) is not positive"),
     INDEX_OUT_OF_RANGE("index {0} out of allowed range [{1}, {2}]"),
+    INDEX("index ({0})"), /* keep */
     INFINITE_ARRAY_ELEMENT("Array contains an infinite element, {0} at index {1}"),
     INFINITE_VALUE_CONVERSION("cannot convert infinite value"),
     INITIAL_CAPACITY_NOT_POSITIVE("initial capacity ({0}) is not positive"),
-    INITIAL_COLUMN_AFTER_FINAL_COLUMN("initial column {0} after final column {1}"),
-    INITIAL_ROW_AFTER_FINAL_ROW("initial row {0} after final row {1}"),
+    INITIAL_COLUMN_AFTER_FINAL_COLUMN("initial column {1} after final column {0}"),
+    INITIAL_ROW_AFTER_FINAL_ROW("initial row {1} after final row {0}"),
     INPUT_DATA_FROM_UNSUPPORTED_DATASOURCE("input data comes from unsupported datasource: {0}, supported sources: {1}, {2}"),
     INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES("instance of class {0} not comparable to existing values"),
     INSUFFICIENT_DATA_FOR_T_STATISTIC("insufficient data for t statistic, needs at least 2, got {0}"),

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java Wed Oct 27 13:16:57 2010
@@ -74,9 +74,8 @@ public abstract class AbstractRealMatrix
     public abstract RealMatrix copy();
 
     /** {@inheritDoc} */
-    public RealMatrix add(RealMatrix m) throws IllegalArgumentException {
-
-        // safety check
+    public RealMatrix add(RealMatrix m) {
+        // Safety check.
         MatrixUtils.checkAdditionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
@@ -92,9 +91,8 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix subtract(final RealMatrix m) throws IllegalArgumentException {
-
-        // safety check
+    public RealMatrix subtract(final RealMatrix m) {
+        // Safety check.
         MatrixUtils.checkSubtractionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
@@ -111,7 +109,6 @@ public abstract class AbstractRealMatrix
 
     /** {@inheritDoc} */
     public RealMatrix scalarAdd(final double d) {
-
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
         final RealMatrix out = createMatrix(rowCount, columnCount);
@@ -126,7 +123,6 @@ public abstract class AbstractRealMatrix
 
     /** {@inheritDoc} */
     public RealMatrix scalarMultiply(final double d) {
-
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
         final RealMatrix out = createMatrix(rowCount, columnCount);
@@ -140,10 +136,8 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix multiply(final RealMatrix m)
-        throws IllegalArgumentException {
-
-        // safety check
+    public RealMatrix multiply(final RealMatrix m) {
+        // Safety check.
         MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final int nRows = getRowDimension();
@@ -164,14 +158,12 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix preMultiply(final RealMatrix m)
-        throws IllegalArgumentException {
+    public RealMatrix preMultiply(final RealMatrix m) {
         return m.multiply(this);
     }
 
     /** {@inheritDoc} */
     public double[][] getData() {
-
         final double[][] data = new double[getRowDimension()][getColumnDimension()];
 
         for (int i = 0; i < data.length; ++i) {
@@ -250,9 +242,7 @@ public abstract class AbstractRealMatrix
 
     /** {@inheritDoc} */
     public RealMatrix getSubMatrix(final int startRow, final int endRow,
-                                   final int startColumn, final int endColumn)
-        throws MatrixIndexException {
-
+                                   final int startColumn, final int endColumn) {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
 
         final RealMatrix subMatrix =
@@ -267,9 +257,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix getSubMatrix(final int[] selectedRows, final int[] selectedColumns)
-        throws MatrixIndexException {
-
+    public RealMatrix getSubMatrix(final int[] selectedRows, final int[] selectedColumns) {
         // safety checks
         MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns);
 
@@ -292,8 +280,7 @@ public abstract class AbstractRealMatrix
     /** {@inheritDoc} */
     public void copySubMatrix(final int startRow, final int endRow,
                               final int startColumn, final int endColumn,
-                              final double[][] destination)
-        throws MatrixIndexException, IllegalArgumentException {
+                              final double[][] destination) {
 
         // safety checks
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
@@ -352,9 +339,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
-        throws MatrixIndexException {
-
+    public void setSubMatrix(final double[][] subMatrix, final int row, final int column) {
         final int nRows = subMatrix.length;
         if (nRows == 0) {
             throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
@@ -386,9 +371,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix getRowMatrix(final int row)
-        throws MatrixIndexException {
-
+    public RealMatrix getRowMatrix(final int row) {
         MatrixUtils.checkRowIndex(this, row);
         final int nCols = getColumnDimension();
         final RealMatrix out = createMatrix(1, nCols);
@@ -415,9 +398,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealMatrix getColumnMatrix(final int column)
-        throws MatrixIndexException {
-
+    public RealMatrix getColumnMatrix(final int column) {
         MatrixUtils.checkColumnIndex(this, column);
         final int nRows = getRowDimension();
         final RealMatrix out = createMatrix(nRows, 1);
@@ -444,8 +425,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealVector getRowVector(final int row)
-        throws MatrixIndexException {
+    public RealVector getRowVector(final int row) {
         return new ArrayRealVector(getRow(row), false);
     }
 
@@ -463,8 +443,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public RealVector getColumnVector(final int column)
-        throws MatrixIndexException {
+    public RealVector getColumnVector(final int column) {
         return new ArrayRealVector(getColumn(column), false);
     }
 
@@ -482,9 +461,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public double[] getRow(final int row)
-        throws MatrixIndexException {
-
+    public double[] getRow(final int row) {
         MatrixUtils.checkRowIndex(this, row);
         final int nCols = getColumnDimension();
         final double[] out = new double[nCols];
@@ -508,9 +485,7 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public double[] getColumn(final int column)
-        throws MatrixIndexException {
-
+    public double[] getColumn(final int column) {
         MatrixUtils.checkColumnIndex(this, column);
         final int nRows = getRowDimension();
         final double[] out = new double[nRows];
@@ -534,24 +509,19 @@ public abstract class AbstractRealMatrix
     }
 
     /** {@inheritDoc} */
-    public abstract double getEntry(int row, int column)
-        throws MatrixIndexException;
+    public abstract double getEntry(int row, int column);
 
     /** {@inheritDoc} */
-    public abstract void setEntry(int row, int column, double value)
-        throws MatrixIndexException;
+    public abstract void setEntry(int row, int column, double value);
 
     /** {@inheritDoc} */
-    public abstract void addToEntry(int row, int column, double increment)
-        throws MatrixIndexException;
+    public abstract void addToEntry(int row, int column, double increment);
 
     /** {@inheritDoc} */
-    public abstract void multiplyEntry(int row, int column, double factor)
-        throws MatrixIndexException;
+    public abstract void multiplyEntry(int row, int column, double factor);
 
     /** {@inheritDoc} */
     public RealMatrix transpose() {
-
         final int nRows = getRowDimension();
         final int nCols = getColumnDimension();
         final RealMatrix out = createMatrix(nCols, nRows);
@@ -750,7 +720,7 @@ public abstract class AbstractRealMatrix
     public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -769,7 +739,7 @@ public abstract class AbstractRealMatrix
     public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -816,7 +786,7 @@ public abstract class AbstractRealMatrix
     public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
-    throws MatrixIndexException, MatrixVisitorException {
+    throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -835,7 +805,7 @@ public abstract class AbstractRealMatrix
     public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
-    throws MatrixIndexException, MatrixVisitorException {
+    throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -863,7 +833,7 @@ public abstract class AbstractRealMatrix
     public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor,
                                        final int startRow, final int endRow,
                                        final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
     }
 
@@ -871,7 +841,7 @@ public abstract class AbstractRealMatrix
     public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor,
                                        final int startRow, final int endRow,
                                        final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java Wed Oct 27 13:16:57 2010
@@ -23,6 +23,7 @@ import java.util.NoSuchElementException;
 import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.commons.math.exception.MathUnsupportedOperationException;
 import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.analysis.BinaryFunction;
 import org.apache.commons.math.analysis.ComposableFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
@@ -64,26 +65,27 @@ public abstract class AbstractRealVector
 
     /**
      * Check if an index is valid.
-     * @param index index to check
-     * @exception MatrixIndexException if index is not valid
+     *
+     * @param index Index to check.
+     * @exception OutOfRangeException if {@code index} is not valid.
      */
-    protected void checkIndex(final int index)
-        throws MatrixIndexException {
-        if (index < 0 || index >= getDimension()) {
-            throw new MatrixIndexException(LocalizedFormats.INDEX_OUT_OF_RANGE,
-                                           index, 0, getDimension() - 1);
+    protected void checkIndex(final int index) {
+        if (index < 0 ||
+            index >= getDimension()) {
+            throw new OutOfRangeException(LocalizedFormats.INDEX,
+                                          index, 0, getDimension() - 1);
         }
     }
 
     /** {@inheritDoc} */
-    public void setSubVector(int index, RealVector v) throws MatrixIndexException {
+    public void setSubVector(int index, RealVector v) {
         checkIndex(index);
         checkIndex(index + v.getDimension() - 1);
         setSubVector(index, v.getData());
     }
 
     /** {@inheritDoc} */
-    public void setSubVector(int index, double[] v) throws MatrixIndexException {
+    public void setSubVector(int index, double[] v) {
         checkIndex(index);
         checkIndex(index + v.length - 1);
         for (int i = 0; i < v.length; i++) {
@@ -92,7 +94,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealVector add(double[] v) throws IllegalArgumentException {
+    public RealVector add(double[] v) {
         double[] result = v.clone();
         Iterator<Entry> it = sparseIterator();
         Entry e;
@@ -103,7 +105,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealVector add(RealVector v) throws IllegalArgumentException {
+    public RealVector add(RealVector v) {
         if (v instanceof ArrayRealVector) {
             double[] values = ((ArrayRealVector)v).getDataRef();
             return add(values);
@@ -119,7 +121,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealVector subtract(double[] v) throws IllegalArgumentException {
+    public RealVector subtract(double[] v) {
         double[] result = v.clone();
         Iterator<Entry> it = sparseIterator();
         Entry e;
@@ -131,7 +133,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealVector subtract(RealVector v) throws IllegalArgumentException {
+    public RealVector subtract(RealVector v) {
         if (v instanceof ArrayRealVector) {
             double[] values = ((ArrayRealVector)v).getDataRef();
             return add(values);
@@ -167,12 +169,12 @@ public abstract class AbstractRealVector
     public abstract AbstractRealVector copy();
 
     /** {@inheritDoc} */
-    public double dotProduct(double[] v) throws IllegalArgumentException {
+    public double dotProduct(double[] v) {
         return dotProduct(new ArrayRealVector(v, false));
     }
 
     /** {@inheritDoc} */
-    public double dotProduct(RealVector v) throws IllegalArgumentException {
+    public double dotProduct(RealVector v) {
         checkVectorDimensions(v);
         double d = 0;
         Iterator<Entry> it = sparseIterator();
@@ -184,17 +186,17 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealVector ebeDivide(double[] v) throws IllegalArgumentException {
+    public RealVector ebeDivide(double[] v) {
         return ebeDivide(new ArrayRealVector(v, false));
     }
 
     /** {@inheritDoc} */
-    public RealVector ebeMultiply(double[] v) throws IllegalArgumentException {
+    public RealVector ebeMultiply(double[] v) {
         return ebeMultiply(new ArrayRealVector(v, false));
     }
 
     /** {@inheritDoc} */
-    public double getDistance(RealVector v) throws IllegalArgumentException {
+    public double getDistance(RealVector v) {
         checkVectorDimensions(v);
         double d = 0;
         Iterator<Entry> it = iterator();
@@ -241,12 +243,12 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public double getDistance(double[] v) throws IllegalArgumentException {
+    public double getDistance(double[] v) {
         return getDistance(new ArrayRealVector(v,false));
     }
 
     /** {@inheritDoc} */
-    public double getL1Distance(RealVector v) throws IllegalArgumentException {
+    public double getL1Distance(RealVector v) {
         checkVectorDimensions(v);
         double d = 0;
         Iterator<Entry> it = iterator();
@@ -258,7 +260,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public double getL1Distance(double[] v) throws IllegalArgumentException {
+    public double getL1Distance(double[] v) {
         checkVectorDimensions(v.length);
         double d = 0;
         Iterator<Entry> it = iterator();
@@ -270,7 +272,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public double getLInfDistance(RealVector v) throws IllegalArgumentException {
+    public double getLInfDistance(RealVector v) {
         checkVectorDimensions(v);
         double d = 0;
         Iterator<Entry> it = iterator();
@@ -282,7 +284,7 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public double getLInfDistance(double[] v) throws IllegalArgumentException {
+    public double getLInfDistance(double[] v) {
         checkVectorDimensions(v.length);
         double d = 0;
         Iterator<Entry> it = iterator();
@@ -720,12 +722,14 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealMatrix outerProduct(RealVector v) throws IllegalArgumentException {
+    public RealMatrix outerProduct(RealVector v) {
         RealMatrix product;
         if (v instanceof SparseRealVector || this instanceof SparseRealVector) {
-            product = new OpenMapRealMatrix(this.getDimension(), v.getDimension());
+            product = new OpenMapRealMatrix(this.getDimension(),
+                                            v.getDimension());
         } else {
-            product = new Array2DRowRealMatrix(this.getDimension(), v.getDimension());
+            product = new Array2DRowRealMatrix(this.getDimension(),
+                                               v.getDimension());
         }
         Iterator<Entry> thisIt = sparseIterator();
         Entry thisE = null;
@@ -743,12 +747,12 @@ public abstract class AbstractRealVector
     }
 
     /** {@inheritDoc} */
-    public RealMatrix outerProduct(double[] v) throws IllegalArgumentException {
+    public RealMatrix outerProduct(double[] v) {
         return outerProduct(new ArrayRealVector(v, false));
     }
 
     /** {@inheritDoc} */
-    public RealVector projection(double[] v) throws IllegalArgumentException {
+    public RealVector projection(double[] v) {
         return projection(new ArrayRealVector(v, false));
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java Wed Oct 27 13:16:57 2010
@@ -19,7 +19,10 @@ package org.apache.commons.math.linear;
 
 import java.io.Serializable;
 
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.ZeroException;
+import org.apache.commons.math.exception.MathIllegalStateException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 
 /**
@@ -51,18 +54,15 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializable {
-
-    /** Serializable version identifier */
+    /** Serializable version identifier. */
     private static final long serialVersionUID = -1067294169172445528L;
-
-    /** Entries of the matrix */
+    /** Entries of the matrix. */
     protected double data[][];
 
     /**
      * Creates a matrix with no data
      */
-    public Array2DRowRealMatrix() {
-    }
+    public Array2DRowRealMatrix() {}
 
     /**
      * Create a new RealMatrix with the supplied row and column dimensions.
@@ -99,40 +99,38 @@ public class Array2DRowRealMatrix extend
     /**
      * Create a new RealMatrix using the input array as the underlying
      * data array.
-     * <p>If an array is built specially in order to be embedded in a
-     * RealMatrix and not used directly, the <code>copyArray</code> may be
-     * set to <code>false</code. This will prevent the copying and improve
-     * performance as no new array will be built and no data will be copied.</p>
-     * @param d data for new matrix
-     * @param copyArray if true, the input array will be copied, otherwise
-     * it will be referenced
-     * @throws IllegalArgumentException if <code>d</code> is not rectangular
-     *  (not all rows have the same length) or empty
-     * @throws NullPointerException if <code>d</code> is null
+     * If an array is built specially in order to be embedded in a
+     * RealMatrix and not used directly, the {@code copyArray} may be
+     * set to {@code false}. This will prevent the copying and improve
+     * performance as no new array will be built and no data will be copied.
+     *
+     * @param d Data for new matrix.
+     * @param copyArray if {@code true}, the input array will be copied,
+     * otherwise it will be referenced.
+     * @throws DimensionMismatchException if {@code d} is not rectangular
+     * (not all rows have the same length) or empty.
+     * @throws NullArgumentException if {@code d} is {@code null}.
+     * @throws ZeroException if there are not at least one row and one column.
      * @see #Array2DRowRealMatrix(double[][])
      */
-    public Array2DRowRealMatrix(final double[][] d, final boolean copyArray)
-        throws IllegalArgumentException, NullPointerException {
+    public Array2DRowRealMatrix(final double[][] d, final boolean copyArray) {
         if (copyArray) {
             copyIn(d);
         } else {
             if (d == null) {
-                throw new NullPointerException();
+                throw new NullArgumentException();
             }
             final int nRows = d.length;
             if (nRows == 0) {
-                throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.AT_LEAST_ONE_ROW);
+                throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_ROW);
             }
             final int nCols = d[0].length;
             if (nCols == 0) {
-                throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.AT_LEAST_ONE_COLUMN);
+                throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
             }
             for (int r = 1; r < nRows; r++) {
                 if (d[r].length != nCols) {
-                    throw MathRuntimeException.createIllegalArgumentException(
-                          LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, d[r].length);
+                    throw new DimensionMismatchException(d[r].length, nCols);
                 }
             }
             data = d;
@@ -140,12 +138,12 @@ public class Array2DRowRealMatrix extend
     }
 
     /**
-     * Create a new (column) RealMatrix using <code>v</code> as the
-     * data for the unique column of the <code>v.length x 1</code> matrix
+     * Create a new (column) RealMatrix using {@code v} as the
+     * data for the unique column of the {@code v.length x 1} matrix
      * created.
-     * <p>The input array is copied, not referenced.</p>
+     * The input array is copied, not referenced.
      *
-     * @param v column vector holding data for new matrix
+     * @param v Column vector holding data for new matrix.
      */
     public Array2DRowRealMatrix(final double[] v) {
         final int nRows = v.length;
@@ -157,8 +155,8 @@ public class Array2DRowRealMatrix extend
 
     /** {@inheritDoc} */
     @Override
-    public RealMatrix createMatrix(final int rowDimension, final int columnDimension)
-        throws IllegalArgumentException {
+    public RealMatrix createMatrix(final int rowDimension,
+                                   final int columnDimension) {
         return new Array2DRowRealMatrix(rowDimension, columnDimension);
     }
 
@@ -168,28 +166,16 @@ public class Array2DRowRealMatrix extend
         return new Array2DRowRealMatrix(copyOut(), false);
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public RealMatrix add(final RealMatrix m)
-        throws IllegalArgumentException {
-        try {
-            return add((Array2DRowRealMatrix) m);
-        } catch (ClassCastException cce) {
-            return super.add(m);
-        }
-    }
-
     /**
-     * Compute the sum of this and <code>m</code>.
+     * Compute the sum of this matrix with {@code m}.
      *
-     * @param m    matrix to be added
-     * @return     this + m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be added.
+     * @return {@code this} + m.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
-    public Array2DRowRealMatrix add(final Array2DRowRealMatrix m)
-        throws IllegalArgumentException {
-
-        // safety check
+    public Array2DRowRealMatrix add(final Array2DRowRealMatrix m) {
+        // Safety check.
         MatrixUtils.checkAdditionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
@@ -205,31 +191,18 @@ public class Array2DRowRealMatrix extend
         }
 
         return new Array2DRowRealMatrix(outData, false);
-
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public RealMatrix subtract(final RealMatrix m)
-        throws IllegalArgumentException {
-        try {
-            return subtract((Array2DRowRealMatrix) m);
-        } catch (ClassCastException cce) {
-            return super.subtract(m);
-        }
     }
 
     /**
-     * Compute  this minus <code>m</code>.
+     * Subtract {@code m} from this matrix.
      *
-     * @param m    matrix to be subtracted
-     * @return     this + m
-     * @throws  IllegalArgumentException if m is not the same size as this
+     * @param m Matrix to be subtracted.
+     * @return {@code this} - m.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if {@code m} is not the same size as this matrix.
      */
-    public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m)
-        throws IllegalArgumentException {
-
-        // safety check
+    public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) {
+        // Safety check.
         MatrixUtils.checkSubtractionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
@@ -245,31 +218,19 @@ public class Array2DRowRealMatrix extend
         }
 
         return new Array2DRowRealMatrix(outData, false);
-
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public RealMatrix multiply(final RealMatrix m)
-        throws IllegalArgumentException {
-        try {
-            return multiply((Array2DRowRealMatrix) m);
-        } catch (ClassCastException cce) {
-            return super.multiply(m);
-        }
     }
 
     /**
-     * Returns the result of postmultiplying this by <code>m</code>.
-     * @param m    matrix to postmultiply by
-     * @return     this*m
-     * @throws     IllegalArgumentException
-     *             if columnDimension(this) != rowDimension(m)
+     * Returns the result of postmultiplying this matrix with {@code m}.
+     *
+     * @param m Matrix to postmultiply by.
+     * @return {@code this} * m.
+     * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+     * if the column dimension of this matrix is different from the row
+     * dimension of {@code m}.
      */
-    public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m)
-        throws IllegalArgumentException {
-
-        // safety check
+    public Array2DRowRealMatrix multiply(final Array2DRowRealMatrix m) {
+        // Safety check.
         MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final int nRows = this.getRowDimension();
@@ -299,11 +260,9 @@ public class Array2DRowRealMatrix extend
     }
 
     /**
-     * Returns a reference to the underlying data array.
-     * <p>
-     * Does <strong>not</strong> make a fresh copy of the underlying data.</p>
+     * Return a reference to the underlying data array.
      *
-     * @return 2-dimensional array of entries
+     * @return 2-dimensional array of entries.
      */
     public double[][] getDataRef() {
         return data;
@@ -311,33 +270,28 @@ public class Array2DRowRealMatrix extend
 
     /** {@inheritDoc} */
     @Override
-    public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
-    throws MatrixIndexException {
+    public void setSubMatrix(final double[][] subMatrix,
+                             final int row, final int column) {
         if (data == null) {
             if (row > 0) {
-                throw MathRuntimeException.createIllegalStateException(
-                      LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
+                throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
             }
             if (column > 0) {
-                throw MathRuntimeException.createIllegalStateException(
-                      LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
+                throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
             }
             final int nRows = subMatrix.length;
             if (nRows == 0) {
-                throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.AT_LEAST_ONE_ROW);
+                throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_ROW);
             }
 
             final int nCols = subMatrix[0].length;
             if (nCols == 0) {
-                throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.AT_LEAST_ONE_COLUMN);
+                throw new ZeroException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
             }
             data = new double[subMatrix.length][nCols];
             for (int i = 0; i < data.length; ++i) {
                 if (subMatrix[i].length != nCols) {
-                    throw MathRuntimeException.createIllegalArgumentException(
-                          LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[i].length);
+                    throw new DimensionMismatchException(subMatrix[i].length, nCols);
                 }
                 System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
             }
@@ -349,55 +303,35 @@ public class Array2DRowRealMatrix extend
 
     /** {@inheritDoc} */
     @Override
-    public double getEntry(final int row, final int column)
-        throws MatrixIndexException {
-        try {
-            return data[row][column];
-        } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException(
-                      LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension());
-        }
+    public double getEntry(final int row, final int column) {
+        MatrixUtils.checkMatrixIndex(this, row, column);
+        return data[row][column];
     }
 
     /** {@inheritDoc} */
     @Override
-    public void setEntry(final int row, final int column, final double value)
-        throws MatrixIndexException {
-        try {
-            data[row][column] = value;
-        } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException(
-                      LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension());
-        }
+    public void setEntry(final int row, final int column, final double value) {
+        MatrixUtils.checkMatrixIndex(this, row, column);
+        data[row][column] = value;
     }
 
     /** {@inheritDoc} */
     @Override
-    public void addToEntry(final int row, final int column, final double increment)
-        throws MatrixIndexException {
-        try {
-            data[row][column] += increment;
-        } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException(
-                      LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension());
-        }
+    public void addToEntry(final int row, final int column, final double increment) {
+        MatrixUtils.checkMatrixIndex(this, row, column);
+        data[row][column] += increment;
     }
 
     /** {@inheritDoc} */
     @Override
-    public void multiplyEntry(final int row, final int column, final double factor)
-        throws MatrixIndexException {
-        try {
-            data[row][column] *= factor;
-        } catch (ArrayIndexOutOfBoundsException e) {
-            throw new MatrixIndexException(
-                      LocalizedFormats.NO_SUCH_MATRIX_ENTRY, row, column, getRowDimension(), getColumnDimension());
-        }
+    public void multiplyEntry(final int row, final int column, final double factor) {
+        MatrixUtils.checkMatrixIndex(this, row, column);
+        data[row][column] *= factor;
     }
 
     /** {@inheritDoc} */
     @Override
-    public int getRowDimension() {
+        public int getRowDimension() {
         return (data == null) ? 0 : data.length;
     }
 
@@ -409,13 +343,11 @@ public class Array2DRowRealMatrix extend
 
     /** {@inheritDoc} */
     @Override
-    public double[] operate(final double[] v)
-        throws IllegalArgumentException {
+    public double[] operate(final double[] v) {
         final int nRows = this.getRowDimension();
         final int nCols = this.getColumnDimension();
         if (v.length != nCols) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nCols);
+            throw new DimensionMismatchException(v.length, nCols);
         }
         final double[] out = new double[nRows];
         for (int row = 0; row < nRows; row++) {
@@ -431,14 +363,11 @@ public class Array2DRowRealMatrix extend
 
     /** {@inheritDoc} */
     @Override
-    public double[] preMultiply(final double[] v)
-        throws IllegalArgumentException {
-
+    public double[] preMultiply(final double[] v) {
         final int nRows = getRowDimension();
         final int nCols = getColumnDimension();
         if (v.length != nRows) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.VECTOR_LENGTH_MISMATCH, v.length, nRows);
+            throw new DimensionMismatchException(v.length, nRows);
         }
 
         final double[] out = new double[nCols];
@@ -491,7 +420,7 @@ public class Array2DRowRealMatrix extend
     public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -509,7 +438,7 @@ public class Array2DRowRealMatrix extend
     public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -558,7 +487,7 @@ public class Array2DRowRealMatrix extend
     public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
@@ -576,7 +505,7 @@ public class Array2DRowRealMatrix extend
     public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
-        throws MatrixIndexException, MatrixVisitorException {
+        throws MatrixVisitorException {
         MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java?rev=1027952&r1=1027951&r2=1027952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayFieldVector.java Wed Oct 27 13:16:57 2010
@@ -22,7 +22,11 @@ import java.util.Arrays;
 
 import org.apache.commons.math.Field;
 import org.apache.commons.math.FieldElement;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.ZeroException;
+import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.OutOfRangeException;
+import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 
 /**
@@ -32,24 +36,22 @@ import org.apache.commons.math.exception
  * @since 2.0
  */
 public class ArrayFieldVector<T extends FieldElement<T>> implements FieldVector<T>, Serializable {
-
     /** Serializable version identifier. */
     private static final long serialVersionUID = 7648186910365927050L;
-
     /** Entries of the vector. */
     protected T[] data;
-
     /** Field to which the elements belong. */
     private final Field<T> field;
 
     /**
      * Build a 0-length vector.
-     * <p>Zero-length vectors may be used to initialized construction of vectors
+     * Zero-length vectors may be used to initialized 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</code> methods ({@link #append(FieldElement[])},
+     * or one of the {@code append} methods ({@link #append(FieldElement[])},
      * {@link #add(FieldVector)}, {@link #append(ArrayFieldVector)}) to gather data
-     * into this vector.</p>
+     * into this vector.
+     *
      * @param field field to which the elements belong
      */
     public ArrayFieldVector(final Field<T> field) {
@@ -57,9 +59,10 @@ public class ArrayFieldVector<T extends 
     }
 
     /**
-     * Construct a (size)-length vector of zeros.
-     * @param field field to which the elements belong
-     * @param size size of the vector
+     * Construct a vector of zeroes.
+     *
+     * @param field Field to which the elements belong.
+     * @param size Size of the vector.
      */
     public ArrayFieldVector(Field<T> field, int size) {
         this.field = field;
@@ -68,9 +71,10 @@ public class ArrayFieldVector<T extends 
     }
 
     /**
-     * Construct an (size)-length vector with preset values.
-     * @param size size of the vector
-     * @param preset fill the vector with this scalar value
+     * Construct a vector with preset values.
+     *
+     * @param size Size of the vector.
+     * @param preset All entries will be set with this value.
      */
     public ArrayFieldVector(int size, T preset) {
         this(preset.getField(), size);
@@ -79,34 +83,40 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector from an array, copying the input array.
-     * <p>
      * This constructor needs a non-empty {@code d} array to retrieve
      * the field from its first element. This implies it cannot build
      * 0 length vectors. To build vectors from any size, one should
      * use the {@link #ArrayFieldVector(Field, FieldElement[])} constructor.
-     * </p>
-     * @param d array of Ts.
-     * @throws IllegalArgumentException if <code>d</code> is empty
+     *
+     * @param d Array.
+     * @throws NullArgumentException if {@code d} is {@code null}.
+     * @throws ZeroException if {@code d} is empty.
      * @see #ArrayFieldVector(Field, FieldElement[])
      */
-    public ArrayFieldVector(T[] d)
-        throws IllegalArgumentException {
+    public ArrayFieldVector(T[] d) {
+        if (d == null) {
+            throw new NullArgumentException();
+        }
         try {
             field = d[0].getField();
             data = d.clone();
         } catch (ArrayIndexOutOfBoundsException e) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
+            throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
         }
     }
 
     /**
      * Construct a vector from an array, copying the input array.
-     * @param field field to which the elements belong
-     * @param d array of Ts.
+     *
+     * @param field Field to which the elements belong.
+     * @param d Array.
+     * @throws NullArgumentException if {@code d} is {@code null}.
      * @see #ArrayFieldVector(FieldElement[])
      */
     public ArrayFieldVector(Field<T> field, T[] d) {
+        if (d == null) {
+            throw new NullArgumentException();
+        }
         this.field = field;
         data = d.clone();
     }
@@ -114,29 +124,30 @@ public class ArrayFieldVector<T extends 
     /**
      * Create a new ArrayFieldVector using the input array as the underlying
      * data array.
-     * <p>If an array is built specially in order to be embedded in a
-     * ArrayFieldVector and not used directly, the <code>copyArray</code> may be
-     * set to <code>false</code. This will prevent the copying and improve
-     * performance as no new array will be built and no data will be copied.</p>
-     * <p>
+     * If an array is built specially in order to be embedded in a
+     * ArrayFieldVector and not used directly, the {@code copyArray} may be
+     * set to {@code false}. This will prevent the copying and improve
+     * performance as no new array will be built and no data will be copied.
      * This constructor needs a non-empty {@code d} array to retrieve
      * the field from its first element. This implies it cannot build
      * 0 length vectors. To build vectors from any size, one should
-     * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)} constructor.
-     * </p>
-     * @param d data for new vector
-     * @param copyArray if true, the input array will be copied, otherwise
-     * it will be referenced
-     * @throws IllegalArgumentException if <code>d</code> is empty
-     * @throws NullPointerException if <code>d</code> is null
+     * use the {@link #ArrayFieldVector(Field, FieldElement[], boolean)}
+     * constructor.
+     *
+     * @param d Data for the new vector.
+     * @param copyArray If {@code true}, the input array will be copied,
+     * otherwise it will be referenced.
+     * @throws NullArgumentException if {@code d} is {@code null}.
+     * @throws ZeroException if {@code d} is empty.
      * @see #ArrayFieldVector(FieldElement[])
      * @see #ArrayFieldVector(Field, FieldElement[], boolean)
      */
-    public ArrayFieldVector(T[] d, boolean copyArray)
-        throws NullPointerException, IllegalArgumentException {
+    public ArrayFieldVector(T[] d, boolean copyArray) {
+        if (d == null) {
+            throw new NullArgumentException();
+        }
         if (d.length == 0) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
+            throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
         }
         field = d[0].getField();
         data = copyArray ? d.clone() :  d;
@@ -145,32 +156,42 @@ public class ArrayFieldVector<T extends 
     /**
      * Create a new ArrayFieldVector using the input array as the underlying
      * data array.
-     * <p>If an array is built specially in order to be embedded in a
-     * ArrayFieldVector and not used directly, the <code>copyArray</code> may be
-     * set to <code>false</code. This will prevent the copying and improve
-     * performance as no new array will be built and no data will be copied.</p>
-     * @param field field to which the elements belong
-     * @param d data for new vector
-     * @param copyArray if true, the input array will be copied, otherwise
-     * it will be referenced
+     * If an array is built specially in order to be embedded in a
+     * ArrayFieldVector and not used directly, the {@code copyArray} may be
+     * set to {@code false}. This will prevent the copying and improve
+     * performance as no new array will be built and no data will be copied.
+     *
+     * @param field Field to which the elements belong.
+     * @param d Data for the new vector.
+     * @param copyArray If {@code true}, the input array will be copied,
+     * otherwise it will be referenced.
+     * @throws NullArgumentException if {@code d} is {@code null}.
      * @see #ArrayFieldVector(FieldElement[], boolean)
      */
     public ArrayFieldVector(Field<T> field, T[] d, boolean copyArray) {
+        if (d == null) {
+            throw new NullArgumentException();
+        }
         this.field = field;
         data = copyArray ? d.clone() :  d;
     }
 
     /**
      * Construct a vector from part of a array.
-     * @param d array of Ts.
-     * @param pos position of first entry
-     * @param size number of entries to copy
+     *
+     * @param d Array.
+     * @param pos Position of the first entry.
+     * @param size Number of entries to copy.
+     * @throws NullArgumentException if {@code d} is {@code null}.
+     * @throws NumberIsTooLargeException if the size of {@code d} is less
+     * than {@code pos + size}.
      */
     public ArrayFieldVector(T[] d, int pos, int size) {
+        if (d == null) {
+            throw new NullArgumentException();
+        }
         if (d.length < pos + size) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                    LocalizedFormats.POSITION_SIZE_MISMATCH_INPUT_ARRAY,
-                    pos, size, d.length);
+            throw new NumberIsTooLargeException(pos + size, d.length, true);
         }
         field = d[0].getField();
         data = buildArray(size);
@@ -179,9 +200,14 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector from another vector, using a deep copy.
-     * @param v vector to copy
+     *
+     * @param v Vector to copy.
+     * @throws NullArgumentException if {@code v} is {@code null}.
      */
     public ArrayFieldVector(FieldVector<T> v) {
+        if (v == null) {
+            throw new NullArgumentException();
+        }
         field = v.getField();
         data = buildArray(v.getDimension());
         for (int i = 0; i < data.length; ++i) {
@@ -191,29 +217,47 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector from another vector, using a deep copy.
-     * @param v vector to copy
+     *
+     * @param v Vector to copy.
+     * @throws NullArgumentException if {@code v} is {@code null}.
      */
     public ArrayFieldVector(ArrayFieldVector<T> v) {
+        if (v == null) {
+            throw new NullArgumentException();
+        }
         field = v.getField();
         data = v.data.clone();
     }
 
     /**
      * Construct a vector from another vector.
-     * @param v vector to copy
-     * @param deep if true perform a deep copy otherwise perform a shallow copy
+     *
+     * @param v Vector to copy.
+     * @param deep If {@code true} perform a deep copy, otherwise perform
+     * a shallow copy
+     * @throws NullArgumentException if {@code v} is {@code null}.
      */
     public ArrayFieldVector(ArrayFieldVector<T> v, boolean deep) {
+        if (v == null) {
+            throw new NullArgumentException();
+        }
         field = v.getField();
         data = deep ? v.data.clone() : v.data;
     }
 
     /**
      * Construct a vector by appending one vector to another vector.
-     * @param v1 first vector (will be put in front of the new vector)
-     * @param v2 second vector (will be put at back of the new vector)
+     *
+     * @param v1 First vector (will be put in front of the new vector).
+     * @param v2 Second vector (will be put at back of the new vector).
+     * @throws NullArgumentException if {@code v1} or {@code v2} is
+     * {@code null}.
      */
     public ArrayFieldVector(ArrayFieldVector<T> v1, ArrayFieldVector<T> v2) {
+        if (v1 == null ||
+            v2 == null) {
+            throw new NullArgumentException();
+        }
         field = v1.getField();
         data = buildArray(v1.data.length + v2.data.length);
         System.arraycopy(v1.data, 0, data, 0, v1.data.length);
@@ -222,10 +266,17 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector by appending one vector to another vector.
-     * @param v1 first vector (will be put in front of the new vector)
-     * @param v2 second vector (will be put at back of the new vector)
+     *
+     * @param v1 First vector (will be put in front of the new vector).
+     * @param v2 Second vector (will be put at back of the new vector).
+     * @throws NullArgumentException if {@code v1} or {@code v2} is
+     * {@code null}.
      */
     public ArrayFieldVector(ArrayFieldVector<T> v1, T[] v2) {
+        if (v1 == null ||
+            v2 == null) {
+            throw new NullArgumentException();
+        }
         field = v1.getField();
         data = buildArray(v1.data.length + v2.length);
         System.arraycopy(v1.data, 0, data, 0, v1.data.length);
@@ -234,10 +285,17 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector by appending one vector to another vector.
-     * @param v1 first vector (will be put in front of the new vector)
-     * @param v2 second vector (will be put at back of the new vector)
+     *
+     * @param v1 First vector (will be put in front of the new vector).
+     * @param v2 Second vector (will be put at back of the new vector).
+     * @throws NullArgumentException if {@code v1} or {@code v2} is
+     * {@code null}.
      */
     public ArrayFieldVector(T[] v1, ArrayFieldVector<T> v2) {
+        if (v1 == null ||
+            v2 == null) {
+            throw new NullArgumentException();
+        }
         field = v2.getField();
         data = buildArray(v1.length + v2.data.length);
         System.arraycopy(v1, 0, data, 0, v1.length);
@@ -246,40 +304,47 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Construct a vector by appending one vector to another vector.
-     * <p>
      * This constructor needs at least one non-empty array to retrieve
      * the field from its first element. This implies it cannot build
      * 0 length vectors. To build vectors from any size, one should
-     * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])} constructor.
-     * </p>
-     * @param v1 first vector (will be put in front of the new vector)
-     * @param v2 second vector (will be put at back of the new vector)
-     * @exception IllegalArgumentException if both vectors are empty
+     * use the {@link #ArrayFieldVector(Field, FieldElement[], FieldElement[])}
+     * constructor.
+     *
+     * @param v1 First vector (will be put in front of the new vector).
+     * @param v2 Second vector (will be put at back of the new vector).
+     * @throws NullArgumentException if {@code v1} or {@code v2} is
+     * {@code null}.
+     * @throws ZeroException if both arrays are empty.
      * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[])
      */
     public ArrayFieldVector(T[] v1, T[] v2) {
-        try {
-            data = buildArray(v1.length + v2.length);
-            System.arraycopy(v1, 0, data, 0, v1.length);
-            System.arraycopy(v2, 0, data, v1.length, v2.length);
-            field = data[0].getField();
-        } catch (ArrayIndexOutOfBoundsException e) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                      LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
+        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);
+        }
+        data = buildArray(v1.length + v2.length);
+        System.arraycopy(v1, 0, data, 0, v1.length);
+        System.arraycopy(v2, 0, data, v1.length, v2.length);
+        field = data[0].getField();
     }
 
     /**
      * Construct a vector by appending one vector to another vector.
-     * @param field field to which the elements belong
-     * @param v1 first vector (will be put in front of the new vector)
-     * @param v2 second vector (will be put at back of the new vector)
+     *
+     * @param field Field to which the elements belong.
+     * @param v1 First vector (will be put in front of the new vector).
+     * @param v2 Second vector (will be put at back of the new vector).
+     * @throws NullArgumentException if {@code v1} or {@code v2} is
+     * {@code null}.
+     * @throws ZeroException if both arrays are empty.
      * @see #ArrayFieldVector(FieldElement[], FieldElement[])
      */
     public ArrayFieldVector(Field<T> field, T[] v1, T[] v2) {
         if (v1.length + v2.length == 0) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                  LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
+            throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT);
         }
         data = buildArray(v1.length + v2.length);
         System.arraycopy(v1, 0, data, 0, v1.length);
@@ -287,9 +352,11 @@ public class ArrayFieldVector<T extends 
         this.field = data[0].getField();
     }
 
-    /** Build an array of elements.
-     * @param length size of the array to build
-     * @return a new array
+    /**
+     * Build an array of elements.
+     *
+     * @param length Size of the array to build.
+     * @return a new array.
      */
     @SuppressWarnings("unchecked") // field is of type T
     private T[] buildArray(final int length) {
@@ -307,7 +374,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> add(FieldVector<T> v) throws IllegalArgumentException {
+    public FieldVector<T> add(FieldVector<T> v) {
         try {
             return add((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -321,7 +388,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> add(T[] v) throws IllegalArgumentException {
+    public FieldVector<T> add(T[] v) {
         checkVectorDimensions(v.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -336,13 +403,12 @@ public class ArrayFieldVector<T extends 
      * @return this + v
      * @throws IllegalArgumentException if v is not the same size as this
      */
-    public ArrayFieldVector<T> add(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public ArrayFieldVector<T> add(ArrayFieldVector<T> v) {
         return (ArrayFieldVector<T>) add(v.data);
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> subtract(FieldVector<T> v) throws IllegalArgumentException {
+    public FieldVector<T> subtract(FieldVector<T> v) {
         try {
             return subtract((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -356,7 +422,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> subtract(T[] v) throws IllegalArgumentException {
+    public FieldVector<T> subtract(T[] v) {
         checkVectorDimensions(v.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -371,8 +437,7 @@ public class ArrayFieldVector<T extends 
      * @return this + v
      * @throws IllegalArgumentException if v is not the same size as this
      */
-    public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public ArrayFieldVector<T> subtract(ArrayFieldVector<T> v) {
         return (ArrayFieldVector<T>) subtract(v.data);
     }
 
@@ -464,8 +529,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeMultiply(FieldVector<T> v)
-        throws IllegalArgumentException {
+    public FieldVector<T> ebeMultiply(FieldVector<T> v) {
         try {
             return ebeMultiply((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -479,8 +543,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeMultiply(T[] v)
-        throws IllegalArgumentException {
+    public FieldVector<T> ebeMultiply(T[] v) {
         checkVectorDimensions(v.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -495,14 +558,12 @@ public class ArrayFieldVector<T extends 
      * @return a vector containing this[i] * v[i] for all i
      * @exception IllegalArgumentException if v is not the same size as this
      */
-    public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v) {
         return (ArrayFieldVector<T>) ebeMultiply(v.data);
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeDivide(FieldVector<T> v)
-        throws IllegalArgumentException {
+    public FieldVector<T> ebeDivide(FieldVector<T> v) {
         try {
             return ebeDivide((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -516,8 +577,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldVector<T> ebeDivide(T[] v)
-        throws IllegalArgumentException {
+    public FieldVector<T> ebeDivide(T[] v) {
         checkVectorDimensions(v.length);
         T[] out = buildArray(data.length);
         for (int i = 0; i < data.length; i++) {
@@ -532,8 +592,7 @@ public class ArrayFieldVector<T extends 
      * @return a vector containing this[i] / v[i] for all i
      * @throws IllegalArgumentException if v is not the same size as this
      */
-    public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v) {
         return (ArrayFieldVector<T>) ebeDivide(v.data);
     }
 
@@ -552,8 +611,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public T dotProduct(FieldVector<T> v)
-        throws IllegalArgumentException {
+    public T dotProduct(FieldVector<T> v) {
         try {
             return dotProduct((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -567,8 +625,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public T dotProduct(T[] v)
-        throws IllegalArgumentException {
+    public T dotProduct(T[] v) {
         checkVectorDimensions(v.length);
         T dot = field.getZero();
         for (int i = 0; i < data.length; i++) {
@@ -583,8 +640,7 @@ public class ArrayFieldVector<T extends 
      * @return the scalar dot product between instance and v
      * @exception IllegalArgumentException if v is not the same size as this
      */
-    public T dotProduct(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public T dotProduct(ArrayFieldVector<T> v) {
         return dotProduct(v.data);
     }
 
@@ -608,8 +664,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public FieldMatrix<T> outerProduct(FieldVector<T> v)
-        throws IllegalArgumentException {
+    public FieldMatrix<T> outerProduct(FieldVector<T> v) {
         try {
             return outerProduct((ArrayFieldVector<T>) v);
         } catch (ClassCastException cce) {
@@ -631,14 +686,12 @@ public class ArrayFieldVector<T extends 
      * @return the square matrix outer product between instance and v
      * @exception IllegalArgumentException if v is not the same size as this
      */
-    public FieldMatrix<T> outerProduct(ArrayFieldVector<T> v)
-        throws IllegalArgumentException {
+    public FieldMatrix<T> outerProduct(ArrayFieldVector<T> v) {
         return outerProduct(v.data);
     }
 
     /** {@inheritDoc} */
-    public FieldMatrix<T> outerProduct(T[] v)
-        throws IllegalArgumentException {
+    public FieldMatrix<T> outerProduct(T[] v) {
         checkVectorDimensions(v.length);
         final int m = data.length;
         final FieldMatrix<T> out = new Array2DRowFieldMatrix<T>(field, m, m);
@@ -651,7 +704,7 @@ public class ArrayFieldVector<T extends 
     }
 
     /** {@inheritDoc} */
-    public T getEntry(int index) throws MatrixIndexException {
+    public T getEntry(int index) {
         return data[index];
     }
 
@@ -743,11 +796,10 @@ public class ArrayFieldVector<T extends 
      *
      * @param index index of first element to be set.
      * @param v vector containing the values to set.
-     * @exception MatrixIndexException if the index is
+     * @throws OutOfRangeException if the index is
      * inconsistent with vector size
      */
-    public void set(int index, ArrayFieldVector<T> v)
-        throws MatrixIndexException {
+    public void set(int index, ArrayFieldVector<T> v) {
         setSubVector(index, v.data);
     }
 
@@ -767,76 +819,56 @@ public class ArrayFieldVector<T extends 
      * @exception IllegalArgumentException if the vectors do not
      * have the same dimension
      */
-    protected void checkVectorDimensions(FieldVector<T> v)
-        throws IllegalArgumentException {
+    protected void checkVectorDimensions(FieldVector<T> v) {
         checkVectorDimensions(v.getDimension());
     }
 
     /**
      * Check if instance dimension is equal to some expected value.
      *
-     * @param n expected dimension.
-     * @exception IllegalArgumentException if the dimension is
-     * inconsistent with vector size
+     * @param n Expected dimension.
+     * @throws OutOfRangeException if the dimension is
+     * inconsistent with this vector size.
      */
-    protected void checkVectorDimensions(int n)
-        throws IllegalArgumentException {
+    protected void checkVectorDimensions(int n) {
         if (data.length != n) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                    LocalizedFormats.VECTOR_LENGTH_MISMATCH,
-                    data.length, n);
+            throw new DimensionMismatchException(data.length, n);
         }
     }
 
     /**
-     * Test for the equality of two real vectors.
-     * <p>
-     * If all coordinates of two real vectors are exactly the same, and none are
-     * <code>Double.NaN</code>, the two real vectors are considered to be equal.
-     * </p>
-     * <p>
-     * <code>NaN</code> coordinates are considered to affect globally the vector
-     * and be equals to each other - i.e, if either (or all) coordinates of the
-     * real vector are equal to <code>Double.NaN</code>, the real vector is equal to
-     * a vector with all <code>Double.NaN</code> coordinates.
-     * </p>
-     *
-     * @param other Object to test for equality to this
-     * @return true if two 3D vector objects are equal, false if
-     *         object is null, not an instance of Vector3D, or
-     *         not equal to this Vector3D instance
+     * Test for the equality of two vectors.
      *
+     * @param other Object to test for equality.
+     * @return {@code true} if two vector objects are equal, {@code false}
+     * otherwise.
      */
     @Override
     public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        }
+        if (other == null) {
+            return false;
+        }
 
-      if (this == other) {
-        return true;
-      }
-
-      if (other == null) {
-        return false;
-      }
-
-      try {
-          @SuppressWarnings("unchecked") // May fail, but we ignore ClassCastException
-          FieldVector<T> rhs = (FieldVector<T>) other;
-          if (data.length != rhs.getDimension()) {
-              return false;
-          }
-
-          for (int i = 0; i < data.length; ++i) {
-              if (!data[i].equals(rhs.getEntry(i))) {
-                  return false;
-              }
-          }
-          return true;
-
-      } catch (ClassCastException ex) {
-          // ignore exception
-          return false;
-      }
+        try {
+            @SuppressWarnings("unchecked") // May fail, but we ignore ClassCastException
+                FieldVector<T> rhs = (FieldVector<T>) other;
+            if (data.length != rhs.getDimension()) {
+                return false;
+            }
 
+            for (int i = 0; i < data.length; ++i) {
+                if (!data[i].equals(rhs.getEntry(i))) {
+                    return false;
+                }
+            }
+            return true;
+        } catch (ClassCastException ex) {
+            // ignore exception
+            return false;
+        }
     }
 
     /**
@@ -855,15 +887,14 @@ public class ArrayFieldVector<T extends 
 
     /**
      * Check if an index is valid.
-     * @param index index to check
-     * @exception MatrixIndexException if index is not valid
+     *
+     * @param index Index to check.
+     * @exception OutOfRangeException if the index is not valid.
      */
-    private void checkIndex(final int index)
-        throws MatrixIndexException {
+    private void checkIndex(final int index) {
         if (index < 0 || index >= getDimension()) {
-            throw new MatrixIndexException(LocalizedFormats.INDEX_OUT_OF_RANGE,
-                                           index, 0, getDimension() - 1);
+            throw new OutOfRangeException(LocalizedFormats.INDEX,
+                                          index, 0, getDimension() - 1);
         }
     }
-
 }