/** * Handles the common {@code Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow, and padding width underflow with * spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision) { return append(seq, formatter, flags, width, precision, ' ', null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param padChar the pad character to use * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final char padChar) { return append(seq, formatter, flags, width, precision, padChar, null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * padding width underflow with spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param ellipsis the ellipsis to use when precision dictates truncation, null or * empty causes a hard truncation * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final CharSequence ellipsis) { return append(seq, formatter, flags, width, precision, ' ', ellipsis); }
@Test public void testDefaultAppend() { assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1).toString()); assertEquals("fo", FormattableUtils.append("foo", new Formatter(), 0, -1, 2).toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1).toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1).toString()); assertEquals(" fo", FormattableUtils.append("foo", new Formatter(), 0, 3, 2).toString()); assertEquals(" fo", FormattableUtils.append("foo", new Formatter(), 0, 5, 2).toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1).toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1).toString()); assertEquals("fo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2).toString()); assertEquals("fo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2).toString()); }
@Test(expected=IllegalArgumentException.class) public void testIllegalEllipsis() { FormattableUtils.append("foo", new Formatter(), 0, -1, 1, "xx"); }
@Test public void testAlternatePadCharacter() { final char pad='_'; assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, pad).toString()); assertEquals("fo", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, pad).toString()); assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, pad).toString()); assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, pad).toString()); assertEquals("_fo", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, pad).toString()); assertEquals("___fo", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, pad).toString()); assertEquals("foo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, pad).toString()); assertEquals("foo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, pad).toString()); assertEquals("fo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, pad).toString()); assertEquals("fo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, pad).toString()); }
@Test public void testAlternatePadCharAndEllipsis() { assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "*").toString()); assertEquals("f*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "*").toString()); assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "*").toString()); assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "*").toString()); assertEquals("_f*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "*").toString()); assertEquals("___f*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "*").toString()); assertEquals("foo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "*").toString()); assertEquals("foo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "*").toString()); assertEquals("f*_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "*").toString()); assertEquals("f*___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "*").toString()); assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "+*").toString()); assertEquals("+*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "+*").toString()); assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "+*").toString()); assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "+*").toString()); assertEquals("_+*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "+*").toString()); assertEquals("___+*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "+*").toString()); assertEquals("foo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "+*").toString()); assertEquals("foo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "+*").toString()); assertEquals("+*_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "+*").toString()); assertEquals("+*___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "+*").toString()); }
@Test public void testEllipsis() { assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "*").toString()); assertEquals("f*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "*").toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "*").toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "*").toString()); assertEquals(" f*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "*").toString()); assertEquals(" f*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "*").toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "*").toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "*").toString()); assertEquals("f* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "*").toString()); assertEquals("f* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "*").toString()); assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "+*").toString()); assertEquals("+*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "+*").toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "+*").toString()); assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "+*").toString()); assertEquals(" +*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "+*").toString()); assertEquals(" +*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "+*").toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "+*").toString()); assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "+*").toString()); assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "+*").toString()); assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "+*").toString()); }
/** * Handles the common {@code Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow, and padding width underflow with * spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision) { return append(seq, formatter, flags, width, precision, ' ', null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param padChar the pad character to use * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final char padChar) { return append(seq, formatter, flags, width, precision, padChar, null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param padChar the pad character to use * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final char padChar) { return append(seq, formatter, flags, width, precision, padChar, null); }
/** * Handles the common {@code Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow, and padding width underflow with * spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision) { return append(seq, formatter, flags, width, precision, ' ', null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * padding width underflow with spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param ellipsis the ellipsis to use when precision dictates truncation, null or * empty causes a hard truncation * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final CharSequence ellipsis) { return append(seq, formatter, flags, width, precision, ' ', ellipsis); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * padding width underflow with spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param ellipsis the ellipsis to use when precision dictates truncation, null or * empty causes a hard truncation * @return the {@code formatter} instance, not null */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final CharSequence ellipsis) { return append(seq, formatter, flags, width, precision, ' ', ellipsis); }
/** * Handles the common {@code Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow, and padding width underflow with * spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @return the {@code formatter} instance, not null */ @GwtIncompatible("incompatible method") public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision) { return append(seq, formatter, flags, width, precision, ' ', null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param padChar the pad character to use * @return the {@code formatter} instance, not null */ @GwtIncompatible("incompatible method") public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final char padChar) { return append(seq, formatter, flags, width, precision, padChar, null); }
/** * Handles the common {@link Formattable} operations of truncate-pad-append, * padding width underflow with spaces. * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} * @param width the width of the output, see {@code Formattable} * @param precision the precision of the output, see {@code Formattable} * @param ellipsis the ellipsis to use when precision dictates truncation, null or * empty causes a hard truncation * @return the {@code formatter} instance, not null */ @GwtIncompatible("incompatible method") public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final CharSequence ellipsis) { return append(seq, formatter, flags, width, precision, ' ', ellipsis); }