@Test public void negativeConvertTest() { Assert.assertEquals("-vi", RomanNumbering.convert(-6)); }
protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); }
RomanNumbering { protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); } }
RomanNumbering { protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); }  }
RomanNumbering { protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); }  static String toRomanLowerCase(int number); static String toRomanUpperCase(int number); static String toRoman(int number, boolean upperCase); }
RomanNumbering { protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); }  static String toRomanLowerCase(int number); static String toRomanUpperCase(int number); static String toRoman(int number, boolean upperCase);  }