code: static String truncateAtMaxLength(String source, int maxLength,
        boolean addEllipsis) {
  
      if (source.length() <= maxLength) {
        return source;
      }
      if (addEllipsis && maxLength > 3) {
        return unicodePreservingSubstring(source, 0, maxLength - 3) + "...";
      }
      return unicodePreservingSubstring(source, 0, maxLength);
    }
docs: If this given string is of length {@code maxLength} or less, it will
  be returned as-is.
  Otherwise, it will be truncated to {@code maxLength}, regardless of whether
  there are any space characters in the String. If an ellipsis is requested
  to be appended to the truncated String, the String will be truncated so
  that the ellipsis will also fit within maxLength.
  If no truncation was necessary, no ellipsis will be added.
  @param source the String to truncate if necessary
  @param maxLength the maximum number of characters to keep
  @param addEllipsis if true, and if the String had to be truncated,
  add "..." to the end of the String before returning. Additionally,
  the ellipsis will only be added if maxLength is greater than 3.
  @return the original string if it's length is less than or equal to
  maxLength, otherwise a truncated string as mentioned above