提交 d90ddbf6 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not initialize private constant arrays in method

上级 d82eb12f
...@@ -31,6 +31,12 @@ public class ToChar { ...@@ -31,6 +31,12 @@ public class ToChar {
*/ */
private static final long JULIAN_EPOCH; private static final long JULIAN_EPOCH;
private static final int[] ROMAN_VALUES = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9,
5, 4, 1 };
private static final String[] ROMAN_NUMERALS = { "M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I" };
static { static {
GregorianCalendar epoch = new GregorianCalendar(Locale.ENGLISH); GregorianCalendar epoch = new GregorianCalendar(Locale.ENGLISH);
epoch.setGregorianChange(new Date(Long.MAX_VALUE)); epoch.setGregorianChange(new Date(Long.MAX_VALUE));
...@@ -410,14 +416,10 @@ public class ToChar { ...@@ -410,14 +416,10 @@ public class ToChar {
} }
private static String toRomanNumeral(int number) { private static String toRomanNumeral(int number) {
int[] values = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9,
5, 4, 1 };
String[] numerals = new String[] { "M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I" };
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
for (int i = 0; i < values.length; i++) { for (int i = 0; i < ROMAN_VALUES.length; i++) {
int value = values[i]; int value = ROMAN_VALUES[i];
String numeral = numerals[i]; String numeral = ROMAN_NUMERALS[i];
while (number >= value) { while (number >= value) {
result.append(numeral); result.append(numeral);
number -= value; number -= value;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论