public static String ensureMinTextLength(final String text,final int neededLen,final char ch,final int mode){
  final int number=neededLen - text.length();
  if (number <= 0) {
    return text;
  }
  final StringBuilder result=new StringBuilder(neededLen);
switch (mode) {
case 0:
{
      for (int i=0; i < number; i++) {
        result.append(ch);
      }
      result.append(text);
    }
  break;
case 1:
{
  result.append(text);
  for (int i=0; i < number; i++) {
    result.append(ch);
  }
}
break;
default :
{
int leftField=number / 2;
int rightField=number - leftField;
while (leftField-- > 0) {
result.append(ch);
}
result.append(text);
while (rightField-- > 0) {
result.append(ch);
}
}
}
return result.toString();
}

public static String ensureMinTextLength ( final String text , final int neededLen , final char ch , final int mode ) { final int number = neededLen - text . length ( ) ; if ( number <= 0 ) { return text ; } final StringBuilder result = new StringBuilder ( neededLen ) ; switch ( mode ) { case 0 : { for ( int i = 0 ; i < number ; i ++ ) { result . append ( ch ) ; } result . append ( text ) ; } break ; case 1 : { result . append ( text ) ; for ( int i = 0 ; i < number ; i ++ ) { result . append ( ch ) ; } } break ; default : { int leftField = number / 2 ; int rightField = number - leftField ; while ( leftField -- > 0 ) { result . append ( ch ) ; } result . append ( text ) ; while ( rightField -- > 0 ) { result . append ( ch ) ; } } } return result . toString ( ) ; }
extend text by chars to needed length .
