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 functions evaluations.
028     *
029     * @version $Revision: 983921 $ $Date: 2010-08-10 12:46:06 +0200 (mar. 10 ao??t 2010) $
030     * @since 2.0
031     */
032    public class MaxEvaluationsExceededException extends ConvergenceException {
033    
034        /** Serializable version identifier. */
035        private static final long serialVersionUID = -5921271447220129118L;
036    
037        /** Maximal number of evaluations allowed. */
038        private final int maxEvaluations;
039    
040        /**
041         * Constructs an exception with a default detail message.
042         * @param maxEvaluations maximal number of evaluations allowed
043         */
044        public MaxEvaluationsExceededException(final int maxEvaluations) {
045            super(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxEvaluations);
046            this.maxEvaluations = maxEvaluations;
047        }
048    
049        /**
050         * Constructs an exception with specified formatted detail message.
051         * Message formatting is delegated to {@link java.text.MessageFormat}.
052         * @param maxEvaluations the exceeded maximal number of evaluations
053         * @param pattern format specifier
054         * @param arguments format arguments
055         * @deprecated as of 2.2 replaced by {@link #MaxEvaluationsExceededException(int, Localizable, Object...)}
056         */
057        @Deprecated
058        public MaxEvaluationsExceededException(final int maxEvaluations,
059                                              final String pattern, final Object ... arguments) {
060            this(maxEvaluations, 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 maxEvaluations the exceeded maximal number of evaluations
067         * @param pattern format specifier
068         * @param arguments format arguments
069         * @since 2.2
070         */
071        public MaxEvaluationsExceededException(final int maxEvaluations,
072                                               final Localizable pattern, final Object ... arguments) {
073            super(pattern, arguments);
074            this.maxEvaluations = maxEvaluations;
075        }
076    
077        /** Get the maximal number of evaluations allowed.
078         * @return maximal number of evaluations allowed
079         */
080        public int getMaxEvaluations() {
081            return maxEvaluations;
082        }
083    
084    }