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 */ 017 package org.apache.commons.math3.linear; 018 019 import org.apache.commons.math3.exception.MultiDimensionMismatchException; 020 import org.apache.commons.math3.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 * @version $Id: MatrixDimensionMismatchException.java 1416643 2012-12-03 19:37:14Z tn $ 028 */ 029 public class MatrixDimensionMismatchException extends MultiDimensionMismatchException { 030 /** Serializable version Id. */ 031 private static final long serialVersionUID = -8415396756375798143L; 032 033 /** 034 * Construct an exception from the mismatched dimensions. 035 * 036 * @param wrongRowDim Wrong row dimension. 037 * @param wrongColDim Wrong column dimension. 038 * @param expectedRowDim Expected row dimension. 039 * @param expectedColDim Expected column dimension. 040 */ 041 public MatrixDimensionMismatchException(int wrongRowDim, 042 int wrongColDim, 043 int expectedRowDim, 044 int expectedColDim) { 045 super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 046 new Integer[] { wrongRowDim, wrongColDim }, 047 new Integer[] { expectedRowDim, expectedColDim }); 048 } 049 050 /** 051 * @return the expected row dimension. 052 */ 053 public int getWrongRowDimension() { 054 return getWrongDimension(0); 055 } 056 /** 057 * @return the expected row dimension. 058 */ 059 public int getExpectedRowDimension() { 060 return getExpectedDimension(0); 061 } 062 /** 063 * @return the wrong column dimension. 064 */ 065 public int getWrongColumnDimension() { 066 return getWrongDimension(1); 067 } 068 /** 069 * @return the expected column dimension. 070 */ 071 public int getExpectedColumnDimension() { 072 return getExpectedDimension(1); 073 } 074 }