001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.legacy.linear;
018
019import org.apache.commons.math4.legacy.exception.MultiDimensionMismatchException;
020import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
021
022/**
023 * Exception to be thrown when either the number of rows or the number of
024 * columns of a matrix do not match the expected values.
025 *
026 * @since 3.0
027 */
028public class MatrixDimensionMismatchException extends MultiDimensionMismatchException {
029    /** Serializable version Id. */
030    private static final long serialVersionUID = -8415396756375798143L;
031
032    /**
033     * Construct an exception from the mismatched dimensions.
034     *
035     * @param wrongRowDim Wrong row dimension.
036     * @param wrongColDim Wrong column dimension.
037     * @param expectedRowDim Expected row dimension.
038     * @param expectedColDim Expected column dimension.
039     */
040    public MatrixDimensionMismatchException(int wrongRowDim,
041                                            int wrongColDim,
042                                            int expectedRowDim,
043                                            int expectedColDim) {
044        super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
045              new Integer[] { wrongRowDim, wrongColDim },
046              new Integer[] { expectedRowDim, expectedColDim });
047    }
048
049    /**
050     * @return the expected row dimension.
051     */
052    public int getWrongRowDimension() {
053        return getWrongDimension(0);
054    }
055    /**
056     * @return the expected row dimension.
057     */
058    public int getExpectedRowDimension() {
059        return getExpectedDimension(0);
060    }
061    /**
062     * @return the wrong column dimension.
063     */
064    public int getWrongColumnDimension() {
065        return getWrongDimension(1);
066    }
067    /**
068     * @return the expected column dimension.
069     */
070    public int getExpectedColumnDimension() {
071        return getExpectedDimension(1);
072    }
073}