@Test public void test_justify_right() throws IOException { assertThat(format( 1, "", 3), is(" 1")); assertThat(format( 12, "", 3), is(" 12")); assertThat(format( 123, "", 3), is("123")); assertThat(format(1234, "", 3), is("1234")); }
@Override public int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position) throws IOException { validateFlags(flags); if (width < 0) { ensureNoInvalidFlags(flags, getPaddingFlags()); return format(formatter, value, locale, flags, precision, formatString, position); } else { Justification j = getJustification(flags); char p = getPaddingChar(flags); StringBuilder sb = new StringBuilder(); int result = format(sb, value, locale, flags, precision, formatString, position); switch (j) { case Left: justifyLeft(formatter, sb, p, width); break; case Center: justifyCenter(formatter, sb, p, width); break; default: justifyRight(formatter, sb, p, width); } return result; } }
FormatAlignmentBase extends FormatConversionBase { @Override public int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position) throws IOException { validateFlags(flags); if (width < 0) { ensureNoInvalidFlags(flags, getPaddingFlags()); return format(formatter, value, locale, flags, precision, formatString, position); } else { Justification j = getJustification(flags); char p = getPaddingChar(flags); StringBuilder sb = new StringBuilder(); int result = format(sb, value, locale, flags, precision, formatString, position); switch (j) { case Left: justifyLeft(formatter, sb, p, width); break; case Center: justifyCenter(formatter, sb, p, width); break; default: justifyRight(formatter, sb, p, width); } return result; } } }
FormatAlignmentBase extends FormatConversionBase { @Override public int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position) throws IOException { validateFlags(flags); if (width < 0) { ensureNoInvalidFlags(flags, getPaddingFlags()); return format(formatter, value, locale, flags, precision, formatString, position); } else { Justification j = getJustification(flags); char p = getPaddingChar(flags); StringBuilder sb = new StringBuilder(); int result = format(sb, value, locale, flags, precision, formatString, position); switch (j) { case Left: justifyLeft(formatter, sb, p, width); break; case Center: justifyCenter(formatter, sb, p, width); break; default: justifyRight(formatter, sb, p, width); } return result; } }  }
FormatAlignmentBase extends FormatConversionBase { @Override public int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position) throws IOException { validateFlags(flags); if (width < 0) { ensureNoInvalidFlags(flags, getPaddingFlags()); return format(formatter, value, locale, flags, precision, formatString, position); } else { Justification j = getJustification(flags); char p = getPaddingChar(flags); StringBuilder sb = new StringBuilder(); int result = format(sb, value, locale, flags, precision, formatString, position); switch (j) { case Left: justifyLeft(formatter, sb, p, width); break; case Center: justifyCenter(formatter, sb, p, width); break; default: justifyRight(formatter, sb, p, width); } return result; } }  @Override int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position); }
FormatAlignmentBase extends FormatConversionBase { @Override public int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position) throws IOException { validateFlags(flags); if (width < 0) { ensureNoInvalidFlags(flags, getPaddingFlags()); return format(formatter, value, locale, flags, precision, formatString, position); } else { Justification j = getJustification(flags); char p = getPaddingChar(flags); StringBuilder sb = new StringBuilder(); int result = format(sb, value, locale, flags, precision, formatString, position); switch (j) { case Left: justifyLeft(formatter, sb, p, width); break; case Center: justifyCenter(formatter, sb, p, width); break; default: justifyRight(formatter, sb, p, width); } return result; } }  @Override int format(FormatterAPI formatter, Object value, Locale locale, String flags, int width, int precision, String formatString, int position);  }