/** * Converts an integer to a string, prepended with a variable amount of '0' * pad characters, and appends it to the given buffer. * * <p>This method is optimized for converting small values to strings. * * @param buf receives integer converted to a string * @param value value to convert to a string * @param size minimum amount of digits to append */ public static void appendPaddedInteger(StringBuffer buf, int value, int size) { try { appendPaddedInteger((Appendable)buf, value, size); } catch (IOException e) { // StringBuffer does not throw IOException } }
/** * Converts an integer to a string, and appends it to the given buffer. * * <p>This method is optimized for converting small values to strings. * * @param buf receives integer converted to a string * @param value value to convert to a string */ public static void appendUnpaddedInteger(StringBuffer buf, int value) { try { appendUnpaddedInteger((Appendable) buf, value); } catch (IOException e) { // StringBuffer do not throw IOException } }
/** * Calculates the number of decimal digits for the given value, * including the sign. */ public static int calculateDigitCount(long value) { if (value < 0) { if (value != Long.MIN_VALUE) { return calculateDigitCount(-value) + 1; } else { return 20; } } return (value < 10 ? 1 : (value < 100 ? 2 : (value < 1000 ? 3 : (value < 10000 ? 4 : ((int)(Math.log(value) / LOG_10) + 1))))); }
public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return; } int value = (int) valueLong; if (iFieldType >= SECONDS_MILLIS) { value = (int) (valueLong / DateTimeConstants.MILLIS_PER_SECOND); } if (iPrefix != null) { iPrefix.printTo(out, value); } int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.writeUnpaddedInteger(out, value); } else { FormatUtils.writePaddedInteger(out, value, minDigits); } if (iFieldType >= SECONDS_MILLIS) { int dp = (int) (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND); if (iFieldType == SECONDS_MILLIS || dp > 0) { out.write('.'); FormatUtils.writePaddedInteger(out, dp, 3); } } if (iSuffix != null) { iSuffix.printTo(out, value); } }
int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.appendUnpaddedInteger(buf, value); } else { FormatUtils.appendPaddedInteger(buf, value, minDigits); FormatUtils.appendPaddedInteger(buf, dp, 3);
long doParseMillis(InternalParser parser, CharSequence text) { int newPos = parser.parseInto(this, text, 0); if (newPos >= 0) { if (newPos >= text.length()) { return computeMillis(true, text); } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text.toString(), newPos)); }
/** * Converts an integer to a string, and writes it to the given writer. * * <p>This method is optimized for converting small values to strings. * * @param out receives integer converted to a string * @param value value to convert to a string */ public static void writeUnpaddedInteger(Writer out, long value) throws IOException { int intValue = (int)value; if (intValue == value) { writeUnpaddedInteger(out, intValue); } else { out.write(Long.toString(value)); } }
writePaddedInteger(out, intValue, size); } else if (size <= 19) { out.write(Long.toString(value));
int hours = FormatUtils.parseTwoDigits(text, position); if (hours > 23) { return ~position; int minutes = FormatUtils.parseTwoDigits(text, position); if (minutes > 59) { return ~position; int seconds = FormatUtils.parseTwoDigits(text, position); if (seconds > 59) { return ~position;
long doParseMillis(InternalParser parser, CharSequence text) { int newPos = parser.parseInto(this, text, 0); if (newPos >= 0) { if (newPos >= text.length()) { return computeMillis(true, text); } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text.toString(), newPos)); }
/** * Converts an integer to a string, and writes it to the given writer. * * <p>This method is optimized for converting small values to strings. * * @param out receives integer converted to a string * @param value value to convert to a string */ public static void writeUnpaddedInteger(Writer out, long value) throws IOException { int intValue = (int)value; if (intValue == value) { writeUnpaddedInteger(out, intValue); } else { out.write(Long.toString(value)); } }
writePaddedInteger(out, intValue, size); } else if (size <= 19) { out.write(Long.toString(value));
public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException { long valueLong = getFieldValue(period); if (valueLong == Long.MAX_VALUE) { return; } int value = (int) valueLong; if (iFieldType >= SECONDS_MILLIS) { value = (int) (valueLong / DateTimeConstants.MILLIS_PER_SECOND); } if (iPrefix != null) { iPrefix.printTo(out, value); } int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.writeUnpaddedInteger(out, value); } else { FormatUtils.writePaddedInteger(out, value, minDigits); } if (iFieldType >= SECONDS_MILLIS) { int dp = (int) (Math.abs(valueLong) % DateTimeConstants.MILLIS_PER_SECOND); if (iFieldType == SECONDS_MILLIS || dp > 0) { out.write('.'); FormatUtils.writePaddedInteger(out, dp, 3); } } if (iSuffix != null) { iSuffix.printTo(out, value); } }
int minDigits = iMinPrintedDigits; if (minDigits <= 1) { FormatUtils.appendUnpaddedInteger(buf, value); } else { FormatUtils.appendPaddedInteger(buf, value, minDigits); FormatUtils.appendPaddedInteger(buf, dp, 3);
int hours = FormatUtils.parseTwoDigits(text, position); if (hours > 23) { return ~position; int minutes = FormatUtils.parseTwoDigits(text, position); if (minutes > 59) { return ~position; int seconds = FormatUtils.parseTwoDigits(text, position); if (seconds > 59) { return ~position;
/** * Converts an integer to a string, prepended with a variable amount of '0' * pad characters, and appends it to the given buffer. * * <p>This method is optimized for converting small values to strings. * * @param buf receives integer converted to a string * @param value value to convert to a string * @param size minimum amount of digits to append */ public static void appendPaddedInteger(StringBuffer buf, long value, int size) { try { appendPaddedInteger((Appendable)buf, value, size); } catch (IOException e) { // StringBuffer does not throw IOException } }
/** * Parses a period from the given text, returning a new MutablePeriod. * * @param text text to parse * @return parsed value in a MutablePeriod object * @throws IllegalArgumentException if any field is out of range */ public MutablePeriod parseMutablePeriod(String text) { checkParser(); MutablePeriod period = new MutablePeriod(0, iParseType); int newPos = getParser().parseInto(period, text, 0, iLocale); if (newPos >= 0) { if (newPos >= text.length()) { return period; } } else { newPos = ~newPos; } throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos)); }
/** * Calculates the number of decimal digits for the given value, * including the sign. */ public static int calculateDigitCount(long value) { if (value < 0) { if (value != Long.MIN_VALUE) { return calculateDigitCount(-value) + 1; } else { return 20; } } return (value < 10 ? 1 : (value < 100 ? 2 : (value < 1000 ? 3 : (value < 10000 ? 4 : ((int)(Math.log(value) / LOG_10) + 1))))); }
/** * Converts an integer to a string, and appends it to the given buffer. * * <p>This method is optimized for converting small values to strings. * * @param buf receives integer converted to a string * @param value value to convert to a string */ public static void appendUnpaddedInteger(StringBuffer buf, long value) { try { appendUnpaddedInteger((Appendable) buf, value); } catch (IOException e) { // StringBuffer do not throw IOException } }
/** * Converts an integer to a string, and writes it to the given writer. * * <p>This method is optimized for converting small values to strings. * * @param out receives integer converted to a string * @param value value to convert to a string */ public static void writeUnpaddedInteger(Writer out, long value) throws IOException { int intValue = (int)value; if (intValue == value) { writeUnpaddedInteger(out, intValue); } else { out.write(Long.toString(value)); } }