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.exception; 018 019import org.apache.commons.math4.legacy.exception.util.Localizable; 020import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; 021 022/** 023 * Exception to be thrown when two sets of dimensions differ. 024 * 025 * @since 3.0 026 */ 027public class MultiDimensionMismatchException extends MathIllegalArgumentException { 028 /** Serializable version Id. */ 029 private static final long serialVersionUID = -8415396756375798143L; 030 031 /** Wrong dimensions. */ 032 private final Integer[] wrong; 033 /** Correct dimensions. */ 034 private final Integer[] expected; 035 036 /** 037 * Construct an exception from the mismatched dimensions. 038 * 039 * @param wrong Wrong dimensions. 040 * @param expected Expected dimensions. 041 */ 042 public MultiDimensionMismatchException(Integer[] wrong, 043 Integer[] expected) { 044 this(LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected); 045 } 046 047 /** 048 * Construct an exception from the mismatched dimensions. 049 * 050 * @param specific Message pattern providing the specific context of 051 * the error. 052 * @param wrong Wrong dimensions. 053 * @param expected Expected dimensions. 054 */ 055 public MultiDimensionMismatchException(Localizable specific, 056 Integer[] wrong, 057 Integer[] expected) { 058 super(specific, wrong, expected); 059 this.wrong = wrong.clone(); 060 this.expected = expected.clone(); 061 } 062 063 /** 064 * @return an array containing the wrong dimensions. 065 */ 066 public Integer[] getWrongDimensions() { 067 return wrong.clone(); 068 } 069 /** 070 * @return an array containing the expected dimensions. 071 */ 072 public Integer[] getExpectedDimensions() { 073 return expected.clone(); 074 } 075 076 /** 077 * @param index Dimension index. 078 * @return the wrong dimension stored at {@code index}. 079 */ 080 public int getWrongDimension(int index) { 081 return wrong[index].intValue(); 082 } 083 /** 084 * @param index Dimension index. 085 * @return the expected dimension stored at {@code index}. 086 */ 087 public int getExpectedDimension(int index) { 088 return expected[index].intValue(); 089 } 090}