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
19 import org.apache.commons.math4.legacy.exception.MultiDimensionMismatchException;
20 import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
21
22 /**
23 * Exception to be thrown when either the number of rows or the number of
24 * columns of a matrix do not match the expected values.
25 *
26 * @since 3.0
27 */
28 public class MatrixDimensionMismatchException extends MultiDimensionMismatchException {
29 /** Serializable version Id. */
30 private static final long serialVersionUID = -8415396756375798143L;
31
32 /**
33 * Construct an exception from the mismatched dimensions.
34 *
35 * @param wrongRowDim Wrong row dimension.
36 * @param wrongColDim Wrong column dimension.
37 * @param expectedRowDim Expected row dimension.
38 * @param expectedColDim Expected column dimension.
39 */
40 public MatrixDimensionMismatchException(int wrongRowDim,
41 int wrongColDim,
42 int expectedRowDim,
43 int expectedColDim) {
44 super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
45 new Integer[] { wrongRowDim, wrongColDim },
46 new Integer[] { expectedRowDim, expectedColDim });
47 }
48
49 /**
50 * @return the expected row dimension.
51 */
52 public int getWrongRowDimension() {
53 return getWrongDimension(0);
54 }
55 /**
56 * @return the expected row dimension.
57 */
58 public int getExpectedRowDimension() {
59 return getExpectedDimension(0);
60 }
61 /**
62 * @return the wrong column dimension.
63 */
64 public int getWrongColumnDimension() {
65 return getWrongDimension(1);
66 }
67 /**
68 * @return the expected column dimension.
69 */
70 public int getExpectedColumnDimension() {
71 return getExpectedDimension(1);
72 }
73 }