public static String abbreviate(final String str, final int maxWidth) {
        if (maxWidth < 4) {
            throw new IllegalArgumentException("Minimum abbreviation width is 4");
        }

        if (N.isNullOrEmpty(str)) {
            return str;
        }

        return str.length() <= maxWidth ? str : str.substring(0, maxWidth - 3) + "...";
    }
public static String abbreviate ( final String str , final int maxWidth ) { if ( maxWidth < 4 ) { throw new IllegalArgumentException ( "Minimum abbreviation width is 4" ) ; } if ( N . isNullOrEmpty ( str ) ) { return str ; } return str . length ( ) <= maxWidth ? str : str . substring ( 0 , maxWidth - 3 ) + "..." ; }
<p>
Abbreviates a String using ellipses. This will turn
"Now is the time for all good men" into "Now is the time for..."
</p>

<p>
Specifically:
</p>
<ul>
<li>If {@code str} is less than or equals to {@code maxWidth} characters
long, return it.</li>
<li>Else abbreviate it to {@code (substring(str, 0, max-3) + "...")}.</li>
<li>If {@code maxWidth} is less than {@code 4}, throw an
{@code IllegalArgumentException}.</li>
<li>In no case will it return a String of length greater than
{@code maxWidth}.</li>
</ul>

<pre>
N.abbreviate(null, *)      = null
N.abbreviate("", 4)        = ""
N.abbreviate("abcdefg", 6) = "abc..."
N.abbreviate("abcdefg", 7) = "abcdefg"
N.abbreviate("abcdefg", 8) = "abcdefg"
N.abbreviate("abcdefg", 4) = "a..."
N.abbreviate("abcdefg", 3) = IllegalArgumentException
</pre>

@param str
the String to check, may be null
@param maxWidth
maximum length of result String, must be at least 4
@return abbreviated String, {@code ""} if null or "" String input
@throws IllegalArgumentException
if the width is too small
@since 2.0