Author: luc Date: Mon Nov 15 19:39:53 2010 New Revision: 1035419 URL: http://svn.apache.org/viewvc?rev=1035419&view=rev Log: added new constructors to MathUserException to provide more control to user
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java?rev=1035419&r1=1035418&r2=1035419&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Mon Nov 15 19:39:53 2010 @@ -19,9 +19,9 @@ package org.apache.commons.math.exceptio import java.util.Locale; import org.apache.commons.math.exception.util.ArgUtils; -import org.apache.commons.math.exception.util.MessageFactory; import org.apache.commons.math.exception.util.Localizable; import org.apache.commons.math.exception.util.LocalizedFormats; +import org.apache.commons.math.exception.util.MessageFactory; /** * This class is intended as a sort of communication channel between @@ -36,40 +36,84 @@ public class MathUserException extends R /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** - * Pattern used to build the message (problem description). + * Pattern used to build the specific part of the message (problem description). */ - private final Localizable pattern; + private final Localizable specific; + /** + * Pattern used to build the general part of the message (problem description). + */ + private final Localizable general; /** * Arguments used to build the message. */ private final Object[] arguments; /** - * Default constructor. + * Build an exception with a default message. */ public MathUserException() { - this(null); + this((Throwable) null); } /** - * @param cause Cause of the error. - * @param args Arguments. + * Build an exception with a default message. + * @param cause Cause of the error (may be null). */ - public MathUserException(Throwable cause, - Object ... args) { - this(null, cause, args); + public MathUserException(final Throwable cause) { + this(cause, LocalizedFormats.USER_EXCEPTION); } /** - * @param pattern Message pattern explaining the cause of the error. - * @param cause Cause of the error. - * @param args Arguments. + * Build an exception with a localizable message. + * @param pattern Format specifier. + * @param arguments Format arguments. */ - public MathUserException(Localizable pattern, - Throwable cause, - Object ... args) { - this.pattern = pattern; - arguments = ArgUtils.flatten(args); + public MathUserException(final Localizable pattern, final Object ... arguments) { + this((Throwable) null, pattern, arguments); + } + + /** + * Build an exception with a localizable message. + * @param cause Cause of the error (may be null). + * @param pattern Format specifier. + * @param arguments Format arguments. + */ + public MathUserException(final Throwable cause, + final Localizable pattern, final Object ... arguments) { + this(cause, (Localizable) null, pattern, arguments); + } + + /** + * Builds an exception from two patterns (specific and general) and + * an argument list. + * + * @param specific Format specifier for the specific part (may be null). + * @param general Format specifier for the general part (may be null). + * @param arguments Format arguments. They will be substituted in + * <em>both</em> the {...@code general} and {...@code specific} format specifiers. + */ + public MathUserException(final Localizable specific, final Localizable general, + final Object ... arguments) { + this((Throwable) null, specific, general, arguments); + } + + /** + * Builds an exception from two patterns (specific and general) and + * an argument list. + * + * @param cause Cause of the error (may be null). + * @param specific Format specifier for the specific part (may be null). + * @param general Format specifier for the general part (may be null). + * @param arguments Format arguments. They will be substituted in + * <em>both</em> the {...@code general} and {...@code specific} format specifiers. + */ + public MathUserException(final Throwable cause, + final Localizable specific, final Localizable general, + final Object ... arguments) { + super(cause); + this.specific = specific; + this.general = general; + this.arguments = ArgUtils.flatten(arguments); } /** @@ -79,10 +123,7 @@ public class MathUserException extends R * @return the localized message. */ public String getMessage(final Locale locale) { - return MessageFactory.buildMessage(locale, - pattern, - LocalizedFormats.USER_EXCEPTION, - arguments); + return MessageFactory.buildMessage(locale, specific, general, arguments); } /** {...@inheritdoc} */