/** * <p>Does this number system contains given digit char? </p> * * @param digit numerical char to be checked * @return boolean * @since 3.11/4.8 */ /*[deutsch] * <p>Enthält dieses Zahlensystem die angegebene Ziffer? </p> * * @param digit numerical char to be checked * @return boolean * @since 3.11/4.8 */ public boolean contains(char digit) { String digits = this.getDigits(); for (int i = 0, n = digits.length(); i < n; i++) { if (digits.charAt(i) == digit) { return true; } } return false; }
/** * <p>Converts given text numeral to an integer in smart mode. </p> * * @param numeral text numeral to be evaluated as number * @return integer * @throws IllegalArgumentException if given number has wrong format * @throws ArithmeticException if int-range overflows * @since 3.11/4.8 */ /*[deutsch] * <p>Konvertiert das angegebene Numeral zu einer Ganzzahl im SMART-Modus. </p> * * @param numeral text numeral to be evaluated as number * @return integer * @throws IllegalArgumentException if given number has wrong format * @throws ArithmeticException if int-range overflows * @since 3.11/4.8 */ public final int toInteger(String numeral) { return this.toInteger(numeral, Leniency.SMART); }
@Override public int toNumeral(int number, Appendable buffer) throws IOException { if (number >= 0) { int count = 0; for (int i = 1; i <= 4; i++) { if (number < D_FACTORS[i]) { count = i; break; } } if (count > 0) { int j = count - 1; do { int q = number / D_FACTORS[j]; buffer.append((q == 11) ? '\u218B' : (q == 10 ? '\u218A' : (char) (q + '0'))); number -= q * D_FACTORS[j]; j--; } while (j >= 0); return count; } } return super.toNumeral(number, buffer); } @Override
/** * <p>Defines the localized zero digit based on given decimal number system. </p> * * @param numberSystem decimal number system * @return changed copy of this instance * @throws IllegalArgumentException if the number system is not decimal * @see #withZeroDigit(char) * @since 3.24/4.20 */ /*[deutsch] * <p>Definiert die lokalisierte Nullziffer, indem das angegebene Dezimalzahlsystem ausgewertet wird. </p> * * @param numberSystem decimal number system * @return changed copy of this instance * @throws IllegalArgumentException if the number system is not decimal * @see #withZeroDigit(char) * @since 3.24/4.20 */ public PrettyTime withZeroDigit(NumberSystem numberSystem) { if (numberSystem.isDecimal()) { return this.withZeroDigit(numberSystem.getDigits().charAt(0)); } else { throw new IllegalArgumentException("Number system is not decimal: " + numberSystem); } }
/** * <p>Converts given integer to a text numeral. </p> * * @param number number to be displayed as text * @return text numeral * @throws IllegalArgumentException if the conversion is not supported for given number * @since 3.11/4.8 */ /*[deutsch] * <p>Konvertiert die angegebene Zahl zu einem Textnumeral. </p> * * @param number number to be displayed as text * @return text numeral * @throws IllegalArgumentException if the conversion is not supported for given number * @since 3.11/4.8 */ public String toNumeral(int number) { if (this.isDecimal() && (number >= 0)) { int delta = this.getDigits().charAt(0) - '0'; String standard = Integer.toString(number); StringBuilder numeral = new StringBuilder(); for (int i = 0, n = standard.length(); i < n; i++) { int codepoint = standard.charAt(i) + delta; numeral.append((char) codepoint); } return numeral.toString(); } else { throw new IllegalArgumentException("Cannot convert: " + number); } }
/** * <p>Converts given integer to a text numeral which will then * be written into buffer. </p> * * @param number number to be displayed as text * @param buffer the buffer where any formatted number goes to * @return count of characters written to the buffer * @throws IllegalArgumentException if the conversion is not supported for given number * @throws IOException if writing to the buffer fails * @since 3.27/4.22 */ /*[deutsch] * <p>Konvertiert die angegebene Zahl zu einem Textnumeral, das * dann in den Puffer geschrieben wird. </p> * * @param number number to be displayed as text * @param buffer the buffer where any formatted number goes to * @return count of characters written to the buffer * @throws IllegalArgumentException if the conversion is not supported for given number * @throws IOException if writing to the buffer fails * @since 3.27/4.22 */ public int toNumeral( int number, Appendable buffer ) throws IOException { String digits = this.toNumeral(number); buffer.append(digits); return digits.length(); }