make the code java 1.3 compatible
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@511531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
177aef7abc
commit
8b48037080
|
@ -101,6 +101,20 @@ public class MathException extends Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a message string by from a pattern and its arguments.
|
||||||
|
* @param pattern format specifier
|
||||||
|
* @param arguments format arguments
|
||||||
|
* @param locale Locale in which the message should be translated
|
||||||
|
* @return a message string
|
||||||
|
*/
|
||||||
|
private static String buildMessage(String pattern, Object[] arguments, Locale locale) {
|
||||||
|
// do it the hard way, for Java 1.3. compatibility
|
||||||
|
MessageFormat mf = new MessageFormat(translate(pattern, locale));
|
||||||
|
mf.setLocale(locale);
|
||||||
|
return mf.format(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>MathException</code> with no
|
* Constructs a new <code>MathException</code> with no
|
||||||
* detail message.
|
* detail message.
|
||||||
|
@ -134,7 +148,7 @@ public class MathException extends Exception {
|
||||||
* @param arguments format arguments
|
* @param arguments format arguments
|
||||||
*/
|
*/
|
||||||
public MathException(String pattern, Object[] arguments) {
|
public MathException(String pattern, Object[] arguments) {
|
||||||
super(new MessageFormat(pattern, Locale.US).format(arguments));
|
super(buildMessage(pattern, arguments, Locale.US));
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
this.rootCause = null;
|
this.rootCause = null;
|
||||||
|
@ -180,7 +194,7 @@ public class MathException extends Exception {
|
||||||
* to be thrown.
|
* to be thrown.
|
||||||
*/
|
*/
|
||||||
public MathException(String pattern, Object[] arguments, Throwable rootCause) {
|
public MathException(String pattern, Object[] arguments, Throwable rootCause) {
|
||||||
super(new MessageFormat(pattern, Locale.US).format(arguments));
|
super(buildMessage(pattern, arguments, Locale.US));
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
this.rootCause = rootCause;
|
this.rootCause = rootCause;
|
||||||
|
@ -209,10 +223,7 @@ public class MathException extends Exception {
|
||||||
* @return localized message
|
* @return localized message
|
||||||
*/
|
*/
|
||||||
public String getMessage(Locale locale) {
|
public String getMessage(Locale locale) {
|
||||||
if (pattern == null) {
|
return (pattern == null) ? null : buildMessage(pattern, arguments, locale);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new MessageFormat(translate(pattern, locale), locale).format(arguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue