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