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.exception.util.Localizable;
021    import org.apache.commons.math.exception.util.LocalizedFormats;
022    
023    /**
024     * Error thrown when a numerical computation exceeds its allowed
025     * number of functions evaluations.
026     *
027     * @version $Id: MaxEvaluationsExceededException.java 1131229 2011-06-03 20:49:25Z luc $
028     * @since 2.0
029     */
030    public class MaxEvaluationsExceededException extends ConvergenceException {
031    
032        /** Serializable version identifier. */
033        private static final long serialVersionUID = -5921271447220129118L;
034    
035        /** Maximal number of evaluations allowed. */
036        private final int maxEvaluations;
037    
038        /**
039         * Constructs an exception with a default detail message.
040         * @param maxEvaluations maximal number of evaluations allowed
041         */
042        public MaxEvaluationsExceededException(final int maxEvaluations) {
043            super(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxEvaluations);
044            this.maxEvaluations = maxEvaluations;
045        }
046    
047        /**
048         * Constructs an exception with specified formatted detail message.
049         * Message formatting is delegated to {@link java.text.MessageFormat}.
050         * @param maxEvaluations the exceeded maximal number of evaluations
051         * @param pattern format specifier
052         * @param arguments format arguments
053         * @since 2.2
054         */
055        public MaxEvaluationsExceededException(final int maxEvaluations,
056                                               final Localizable pattern, final Object ... arguments) {
057            super(pattern, arguments);
058            this.maxEvaluations = maxEvaluations;
059        }
060    
061        /** Get the maximal number of evaluations allowed.
062         * @return maximal number of evaluations allowed
063         */
064        public int getMaxEvaluations() {
065            return maxEvaluations;
066        }
067    
068    }