code: 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);
          }
        }
        break;
      }
      return result.toString();
    }
docs: Extend text by chars to needed length.
  
  @param text      text to be extended, must not be null.
  @param neededLen needed length for text
  @param ch        char to be used for extending
  @param mode      0 to extend left, 1 to extend right, otherwise extends both
  sides
  @return text extended by chars up to needed length, or non-changed if the
  text has equals or greater length.
  @since 1.1