public static String compact ( String input , int limitTo ) { if ( input == null || input . length ( ) <= limitTo ) { return input ; } int headLength = limitTo / 2 ; int tailLength = limitTo - SHRINKED_STRING . length ( ) - headLength ; if ( tailLength < 0 ) { tailLength = 1 ; } return input . substring ( 0 , headLength ) + SHRINKED_STRING + input . substring ( input . length ( ) - tailLength ) ; }
Shrinks the middle of the input string if it is too long so it does not exceed limitTo .