@ Nonnull private static String _getWithLeadingOrTrailing ( @ Nullable final String sSrc , @ Nonnegative final int nMinLen , final char cGap , final boolean bLeading ) { if ( nMinLen <= 0 ) { // Requested length is too short - return as is return getNotNull ( sSrc , "" ) ; } final int nSrcLen = getLength ( sSrc ) ; if ( nSrcLen == 0 ) { // Input string is empty return getRepeated ( cGap , nMinLen ) ; } final int nCharsToAdd = nMinLen - nSrcLen ; if ( nCharsToAdd <= 0 ) { // Input string is already longer than requested minimum length return sSrc ; } final StringBuilder aSB = new StringBuilder ( nMinLen ) ; if ( ! bLeading ) aSB . append ( sSrc ) ; for ( int i = 0 ; i < nCharsToAdd ; ++ i ) aSB . append ( cGap ) ; if ( bLeading ) aSB . append ( sSrc ) ; return aSB . toString ( ) ; }
Get the result string with at least the desired length and fill the lead or trail with the provided char