- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
// gotta love this hack
final private static String PADDING =
" ";
private static String stringFormat(String stringToFormat, int fieldSize, boolean rightJustify) {
// and Java doesn't really excel at this kind of thing either
if (stringToFormat.length() >= fieldSize) {
return stringToFormat.substring(0, fieldSize);
} else {
return rightJustify ?
PADDING.substring(0, fieldSize - stringToFormat.length()) + stringToFormat:
stringToFormat + PADDING.substring(0, fieldSize - stringToFormat.length());
}
}
fieldSize > stringToFormat.length() + PADDING.length()
остальное не ГК.