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 package org.apache.commons.math;
018
019 import org.apache.commons.math.exception.util.DummyLocalizable;
020 import org.apache.commons.math.exception.util.Localizable;
021 import org.apache.commons.math.exception.util.LocalizedFormats;
022 import org.apache.commons.math.linear.ArrayRealVector;
023
024 /**
025 * Exception thrown when an error occurs evaluating a function.
026 * <p>
027 * Maintains an <code>argument</code> property holding the input value that
028 * caused the function evaluation to fail.
029 *
030 * @version $Revision: 1070725 $ $Date: 2011-02-15 02:31:12 +0100 (mar. 15 f??vr. 2011) $
031 */
032 public class FunctionEvaluationException extends MathException {
033
034 /** Serializable version identifier. */
035 private static final long serialVersionUID = 1384427981840836868L;
036
037 /** Argument causing function evaluation failure */
038 private double[] argument;
039
040 /**
041 * Construct an exception indicating the argument value
042 * that caused the function evaluation to fail.
043 *
044 * @param argument the failing function argument
045 */
046 public FunctionEvaluationException(double argument) {
047 super(LocalizedFormats.EVALUATION_FAILED, argument);
048 this.argument = new double[] { argument };
049 }
050
051 /**
052 * Construct an exception indicating the argument value
053 * that caused the function evaluation to fail.
054 *
055 * @param argument the failing function argument
056 * @since 2.0
057 */
058 public FunctionEvaluationException(double[] argument) {
059 super(LocalizedFormats.EVALUATION_FAILED, new ArrayRealVector(argument));
060 this.argument = argument.clone();
061 }
062
063 /**
064 * Constructs an exception with specified formatted detail message.
065 * Message formatting is delegated to {@link java.text.MessageFormat}.
066 * @param argument the failing function argument
067 * @param pattern format specifier
068 * @param arguments format arguments
069 * @since 1.2
070 */
071 public FunctionEvaluationException(double argument,
072 String pattern, Object ... arguments) {
073 this(argument, new DummyLocalizable(pattern), arguments);
074 }
075
076 /**
077 * Constructs an exception with specified formatted detail message.
078 * Message formatting is delegated to {@link java.text.MessageFormat}.
079 * @param argument the failing function argument
080 * @param pattern format specifier
081 * @param arguments format arguments
082 * @since 2.2
083 */
084 public FunctionEvaluationException(double argument,
085 Localizable pattern, Object ... arguments) {
086 super(pattern, arguments);
087 this.argument = new double[] { argument };
088 }
089
090 /**
091 * Constructs an exception with specified formatted detail message.
092 * Message formatting is delegated to {@link java.text.MessageFormat}.
093 * @param argument the failing function argument
094 * @param pattern format specifier
095 * @param arguments format arguments
096 * @since 2.0
097 */
098 public FunctionEvaluationException(double[] argument,
099 String pattern, Object ... arguments) {
100 this(argument, new DummyLocalizable(pattern), arguments);
101 }
102
103 /**
104 * Constructs an exception with specified formatted detail message.
105 * Message formatting is delegated to {@link java.text.MessageFormat}.
106 * @param argument the failing function argument
107 * @param pattern format specifier
108 * @param arguments format arguments
109 * @since 2.2
110 */
111 public FunctionEvaluationException(double[] argument,
112 Localizable pattern, Object ... arguments) {
113 super(pattern, arguments);
114 this.argument = argument.clone();
115 }
116
117 /**
118 * Constructs an exception with specified root cause.
119 * Message formatting is delegated to {@link java.text.MessageFormat}.
120 * @param cause the exception or error that caused this exception to be thrown
121 * @param argument the failing function argument
122 * @since 1.2
123 */
124 public FunctionEvaluationException(Throwable cause, double argument) {
125 super(cause);
126 this.argument = new double[] { argument };
127 }
128
129 /**
130 * Constructs an exception with specified root cause.
131 * Message formatting is delegated to {@link java.text.MessageFormat}.
132 * @param cause the exception or error that caused this exception to be thrown
133 * @param argument the failing function argument
134 * @since 2.0
135 */
136 public FunctionEvaluationException(Throwable cause, double[] argument) {
137 super(cause);
138 this.argument = argument.clone();
139 }
140
141 /**
142 * Constructs an exception with specified formatted detail message and root cause.
143 * Message formatting is delegated to {@link java.text.MessageFormat}.
144 * @param cause the exception or error that caused this exception to be thrown
145 * @param argument the failing function argument
146 * @param pattern format specifier
147 * @param arguments format arguments
148 * @since 1.2
149 */
150 public FunctionEvaluationException(Throwable cause,
151 double argument, String pattern,
152 Object ... arguments) {
153 this(cause, argument, new DummyLocalizable(pattern), arguments);
154 }
155
156 /**
157 * Constructs an exception with specified formatted detail message and root cause.
158 * Message formatting is delegated to {@link java.text.MessageFormat}.
159 * @param cause the exception or error that caused this exception to be thrown
160 * @param argument the failing function argument
161 * @param pattern format specifier
162 * @param arguments format arguments
163 * @since 2.2
164 */
165 public FunctionEvaluationException(Throwable cause,
166 double argument, Localizable pattern,
167 Object ... arguments) {
168 super(cause, pattern, arguments);
169 this.argument = new double[] { argument };
170 }
171
172 /**
173 * Constructs an exception with specified formatted detail message and root cause.
174 * Message formatting is delegated to {@link java.text.MessageFormat}.
175 * @param cause the exception or error that caused this exception to be thrown
176 * @param argument the failing function argument
177 * @param pattern format specifier
178 * @param arguments format arguments
179 * @since 2.0
180 */
181 public FunctionEvaluationException(Throwable cause,
182 double[] argument, String pattern,
183 Object ... arguments) {
184 this(cause, argument, new DummyLocalizable(pattern), arguments);
185 }
186
187 /**
188 * Constructs an exception with specified formatted detail message and root cause.
189 * Message formatting is delegated to {@link java.text.MessageFormat}.
190 * @param cause the exception or error that caused this exception to be thrown
191 * @param argument the failing function argument
192 * @param pattern format specifier
193 * @param arguments format arguments
194 * @since 2.2
195 */
196 public FunctionEvaluationException(Throwable cause,
197 double[] argument, Localizable pattern,
198 Object ... arguments) {
199 super(cause, pattern, arguments);
200 this.argument = argument.clone();
201 }
202
203 /**
204 * Returns the function argument that caused this exception.
205 *
206 * @return argument that caused function evaluation to fail
207 */
208 public double[] getArgument() {
209 return argument.clone();
210 }
211 }