Raymond | dee0849 | 2015-04-02 10:43:13 -0700 | [diff] [blame] | 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 | |
| 18 | package org.apache.commons.math; |
| 19 | |
| 20 | import org.apache.commons.math.ConvergenceException; |
| 21 | import org.apache.commons.math.exception.util.DummyLocalizable; |
| 22 | import org.apache.commons.math.exception.util.Localizable; |
| 23 | import org.apache.commons.math.exception.util.LocalizedFormats; |
| 24 | |
| 25 | /** |
| 26 | * Error thrown when a numerical computation exceeds its allowed |
| 27 | * number of functions evaluations. |
| 28 | * |
| 29 | * @version $Revision: 983921 $ $Date: 2010-08-10 12:46:06 +0200 (mar. 10 août 2010) $ |
| 30 | * @since 2.0 |
| 31 | */ |
| 32 | public class MaxEvaluationsExceededException extends ConvergenceException { |
| 33 | |
| 34 | /** Serializable version identifier. */ |
| 35 | private static final long serialVersionUID = -5921271447220129118L; |
| 36 | |
| 37 | /** Maximal number of evaluations allowed. */ |
| 38 | private final int maxEvaluations; |
| 39 | |
| 40 | /** |
| 41 | * Constructs an exception with a default detail message. |
| 42 | * @param maxEvaluations maximal number of evaluations allowed |
| 43 | */ |
| 44 | public MaxEvaluationsExceededException(final int maxEvaluations) { |
| 45 | super(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxEvaluations); |
| 46 | this.maxEvaluations = maxEvaluations; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructs an exception with specified formatted detail message. |
| 51 | * Message formatting is delegated to {@link java.text.MessageFormat}. |
| 52 | * @param maxEvaluations the exceeded maximal number of evaluations |
| 53 | * @param pattern format specifier |
| 54 | * @param arguments format arguments |
| 55 | * @deprecated as of 2.2 replaced by {@link #MaxEvaluationsExceededException(int, Localizable, Object...)} |
| 56 | */ |
| 57 | @Deprecated |
| 58 | public MaxEvaluationsExceededException(final int maxEvaluations, |
| 59 | final String pattern, final Object ... arguments) { |
| 60 | this(maxEvaluations, 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 maxEvaluations the exceeded maximal number of evaluations |
| 67 | * @param pattern format specifier |
| 68 | * @param arguments format arguments |
| 69 | * @since 2.2 |
| 70 | */ |
| 71 | public MaxEvaluationsExceededException(final int maxEvaluations, |
| 72 | final Localizable pattern, final Object ... arguments) { |
| 73 | super(pattern, arguments); |
| 74 | this.maxEvaluations = maxEvaluations; |
| 75 | } |
| 76 | |
| 77 | /** Get the maximal number of evaluations allowed. |
| 78 | * @return maximal number of evaluations allowed |
| 79 | */ |
| 80 | public int getMaxEvaluations() { |
| 81 | return maxEvaluations; |
| 82 | } |
| 83 | |
| 84 | } |