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 018 package org.apache.commons.math; 019 020 import org.apache.commons.math.ConvergenceException; 021 import org.apache.commons.math.exception.util.DummyLocalizable; 022 import org.apache.commons.math.exception.util.Localizable; 023 import org.apache.commons.math.exception.util.LocalizedFormats; 024 025 /** 026 * Error thrown when a numerical computation exceeds its allowed 027 * number of iterations. 028 * 029 * @version $Revision: 1070725 $ $Date: 2011-02-15 02:31:12 +0100 (mar. 15 f??vr. 2011) $ 030 * @since 1.2 031 */ 032 public class MaxIterationsExceededException extends ConvergenceException { 033 034 /** Serializable version identifier. */ 035 private static final long serialVersionUID = -7821226672760574694L; 036 037 /** Maximal number of iterations allowed. */ 038 private final int maxIterations; 039 040 /** 041 * Constructs an exception with a default detail message. 042 * @param maxIterations maximal number of iterations allowed 043 */ 044 public MaxIterationsExceededException(final int maxIterations) { 045 super(LocalizedFormats.MAX_ITERATIONS_EXCEEDED, maxIterations); 046 this.maxIterations = maxIterations; 047 } 048 049 /** 050 * Constructs an exception with specified formatted detail message. 051 * Message formatting is delegated to {@link java.text.MessageFormat}. 052 * @param maxIterations the exceeded maximal number of iterations 053 * @param pattern format specifier 054 * @param arguments format arguments 055 * @deprecated as of 2.2 replaced by {@link #MaxIterationsExceededException(int, Localizable, Object...)} 056 */ 057 @Deprecated 058 public MaxIterationsExceededException(final int maxIterations, 059 final String pattern, final Object ... arguments) { 060 this(maxIterations, new DummyLocalizable(pattern), arguments); 061 } 062 063 /** 064 * Constructs an exception with specified formatted detail message. 065 * Message formatting is delegated to {@link java.text.MessageFormat}. 066 * @param maxIterations the exceeded maximal number of iterations 067 * @param pattern format specifier 068 * @param arguments format arguments 069 * @since 2.2 070 */ 071 public MaxIterationsExceededException(final int maxIterations, 072 final Localizable pattern, final Object ... arguments) { 073 super(pattern, arguments); 074 this.maxIterations = maxIterations; 075 } 076 077 /** Get the maximal number of iterations allowed. 078 * @return maximal number of iterations allowed 079 */ 080 public int getMaxIterations() { 081 return maxIterations; 082 } 083 084 }