code: static String normalizeString(String string, int desiredLength) {
      if (string == null || string.length() == 0) {
        throw new IllegalArgumentException("Must supply a non-null, non-empty string.");
      }
      if (desiredLength <= 0) {
        throw new IllegalArgumentException("Desired length must be greater than zero.");
      }
      if (string.length() >= desiredLength) {
        return string.substring(0, desiredLength);
      } else {
        StringBuilder builder = new StringBuilder(string);
        while (builder.length() < desiredLength) {
          builder.append(string);
        }
        return builder.substring(0, desiredLength);
      }
    }
docs: Normalize a string to a desired length by repeatedly appending itself and/or truncating.
  
  @param string Input string.
  @param desiredLength Desired length of string.
  @return Output string which is guaranteed to have a length equal to the desired length
  argument.
  @throws IllegalArgumentException if {@code string} is blank or {@code desiredLength} is not
  greater than 0.