1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.commons.math;
19
20import org.apache.commons.math.ConvergenceException;
21import org.apache.commons.math.exception.util.DummyLocalizable;
22import org.apache.commons.math.exception.util.Localizable;
23import org.apache.commons.math.exception.util.LocalizedFormats;
24
25/**
26 * Error thrown when a numerical computation exceeds its allowed
27 * number of iterations.
28 *
29 * @version $Revision: 1070725 $ $Date: 2011-02-15 02:31:12 +0100 (mar. 15 févr. 2011) $
30 * @since 1.2
31 */
32public class MaxIterationsExceededException extends ConvergenceException {
33
34    /** Serializable version identifier. */
35    private static final long serialVersionUID = -7821226672760574694L;
36
37    /** Maximal number of iterations allowed. */
38    private final int maxIterations;
39
40    /**
41     * Constructs an exception with a default detail message.
42     * @param maxIterations maximal number of iterations allowed
43     */
44    public MaxIterationsExceededException(final int maxIterations) {
45        super(LocalizedFormats.MAX_ITERATIONS_EXCEEDED, maxIterations);
46        this.maxIterations = maxIterations;
47    }
48
49    /**
50     * Constructs an exception with specified formatted detail message.
51     * Message formatting is delegated to {@link java.text.MessageFormat}.
52     * @param maxIterations the exceeded maximal number of iterations
53     * @param pattern format specifier
54     * @param arguments format arguments
55     * @deprecated as of 2.2 replaced by {@link #MaxIterationsExceededException(int, Localizable, Object...)}
56     */
57    @Deprecated
58    public MaxIterationsExceededException(final int maxIterations,
59                                          final String pattern, final Object ... arguments) {
60        this(maxIterations, new DummyLocalizable(pattern), arguments);
61    }
62
63    /**
64     * Constructs an exception with specified formatted detail message.
65     * Message formatting is delegated to {@link java.text.MessageFormat}.
66     * @param maxIterations the exceeded maximal number of iterations
67     * @param pattern format specifier
68     * @param arguments format arguments
69     * @since 2.2
70     */
71    public MaxIterationsExceededException(final int maxIterations,
72                                           final Localizable pattern, final Object ... arguments) {
73        super(pattern, arguments);
74        this.maxIterations = maxIterations;
75    }
76
77    /** Get the maximal number of iterations allowed.
78     * @return maximal number of iterations allowed
79     */
80    public int getMaxIterations() {
81        return maxIterations;
82    }
83
84}
85