MatrixDimensionMismatchException.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.math4.legacy.linear;

  18. import org.apache.commons.math4.legacy.exception.MultiDimensionMismatchException;
  19. import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;

  20. /**
  21.  * Exception to be thrown when either the number of rows or the number of
  22.  * columns of a matrix do not match the expected values.
  23.  *
  24.  * @since 3.0
  25.  */
  26. public class MatrixDimensionMismatchException extends MultiDimensionMismatchException {
  27.     /** Serializable version Id. */
  28.     private static final long serialVersionUID = -8415396756375798143L;

  29.     /**
  30.      * Construct an exception from the mismatched dimensions.
  31.      *
  32.      * @param wrongRowDim Wrong row dimension.
  33.      * @param wrongColDim Wrong column dimension.
  34.      * @param expectedRowDim Expected row dimension.
  35.      * @param expectedColDim Expected column dimension.
  36.      */
  37.     public MatrixDimensionMismatchException(int wrongRowDim,
  38.                                             int wrongColDim,
  39.                                             int expectedRowDim,
  40.                                             int expectedColDim) {
  41.         super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
  42.               new Integer[] { wrongRowDim, wrongColDim },
  43.               new Integer[] { expectedRowDim, expectedColDim });
  44.     }

  45.     /**
  46.      * @return the expected row dimension.
  47.      */
  48.     public int getWrongRowDimension() {
  49.         return getWrongDimension(0);
  50.     }
  51.     /**
  52.      * @return the expected row dimension.
  53.      */
  54.     public int getExpectedRowDimension() {
  55.         return getExpectedDimension(0);
  56.     }
  57.     /**
  58.      * @return the wrong column dimension.
  59.      */
  60.     public int getWrongColumnDimension() {
  61.         return getWrongDimension(1);
  62.     }
  63.     /**
  64.      * @return the expected column dimension.
  65.      */
  66.     public int getExpectedColumnDimension() {
  67.         return getExpectedDimension(1);
  68.     }
  69. }