| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.apache.commons.nabla; |
| 18 | |
|
| 19 | |
import java.util.Locale; |
| 20 | |
import java.util.MissingResourceException; |
| 21 | |
import java.util.ResourceBundle; |
| 22 | |
|
| 23 | |
import org.apache.commons.math3.exception.util.Localizable; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 24 | public enum NablaMessages implements Localizable { |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | 1 | CANNOT_READ_CLASS("class {0} cannot be read ({1})"), |
| 46 | 1 | CANNOT_INSTANTIATE_ABSTRACT_CLASS("abstract class {0} cannot be instantiated ({1})"), |
| 47 | 1 | ILLEGAL_ACCESS_TO_CONSTRUCTOR("illegal access to class {0} constructor ({1})"), |
| 48 | 1 | CANNOT_BUILD_CLASS_FROM_OTHER_CLASS("class {0} cannot be built from an instance of class {1} ({2})"), |
| 49 | 1 | CANNOT_INSTANTIATE_CLASS_FROM_OTHER_INSTANCE("class {0} instantiation from an instance of class {1} failed ({2})"), |
| 50 | 1 | INCORRECT_GENERATED_CODE("class {0} code generated from an instance of class {1} is incorrect ({2})"), |
| 51 | 1 | INTERFACE_NOT_FOUND_WHILE_DIFFERENTIATING("interface {0} not found while differentiating class {1}"), |
| 52 | 1 | CLASS_DOES_NOT_IMPLEMENT_INTERFACE("the {0} class does not implement the {1} interface"), |
| 53 | 1 | UNABLE_TO_ANALYZE_METHOD("unable to analyze the {0}.{1} method ({2})"), |
| 54 | 1 | UNKNOWN_METHOD("unknown method {0}.{1}"), |
| 55 | 1 | NUMBER_OF_TEMPORARY_VARIABLES_OUT_OF_RANGE("number of temporary variable ({0}) outside of [{1}, {2}] range"), |
| 56 | 1 | INDEX_OF_LOCAL_VARIABLE_OUT_OF_RANGE("index of size {0} local variable ({1}) outside of [{2}, {3}] range"), |
| 57 | 1 | UNEXPECTED_INSTRUCTION("unexpected instruction with opcode {0}"), |
| 58 | 1 | UNABLE_TO_HANDLE_INSTRUCTION("unable to handle instruction with opcode {0}"), |
| 59 | 1 | CANNOT_GET_VOID_FIELD("unable to get value of void type field {0}"), |
| 60 | 1 | ILLEGAL_LDC_CONSTANT("illegal LDC constant {0}"), |
| 61 | 1 | INTERNAL_ERROR("internal error, please fill a bug report at {0}"); |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
private final String sourceFormat; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 17 | private NablaMessages(final String sourceFormat) { |
| 75 | 17 | this.sourceFormat = sourceFormat; |
| 76 | 17 | } |
| 77 | |
|
| 78 | |
|
| 79 | |
public String getSourceString() { |
| 80 | 34 | return sourceFormat; |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
public String getLocalizedString(final Locale locale) { |
| 85 | |
try { |
| 86 | 51 | final String path = NablaMessages.class.getName().replaceAll("\\.", "/"); |
| 87 | 51 | final ResourceBundle bundle = |
| 88 | |
ResourceBundle.getBundle("assets/" + path, locale); |
| 89 | 34 | if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) { |
| 90 | |
|
| 91 | 34 | return bundle.getString(toString()); |
| 92 | |
} |
| 93 | |
|
| 94 | 17 | } catch (MissingResourceException mre) { |
| 95 | |
|
| 96 | 0 | } |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | 17 | return sourceFormat; |
| 101 | |
|
| 102 | |
} |
| 103 | |
|
| 104 | |
} |