@@ -4295,7 +4295,7 @@ public static String join(final Iterator<?> iterator, final char separator) {
42954295 if (!iterator .hasNext ()) {
42964296 return EMPTY ;
42974297 }
4298- return Streams .of (iterator ).collect (LangCollectors .joining (toStringOrEmpty (String .valueOf (separator )), EMPTY , EMPTY , StringUtils ::toStringOrEmpty ));
4298+ return Streams .of (iterator ).collect (LangCollectors .joining (toString (String .valueOf (separator )), EMPTY , EMPTY , StringUtils ::toString ));
42994299 }
43004300
43014301 /**
@@ -4319,7 +4319,7 @@ public static String join(final Iterator<?> iterator, final String separator) {
43194319 if (!iterator .hasNext ()) {
43204320 return EMPTY ;
43214321 }
4322- return Streams .of (iterator ).collect (LangCollectors .joining (toStringOrEmpty (separator ), EMPTY , EMPTY , StringUtils ::toStringOrEmpty ));
4322+ return Streams .of (iterator ).collect (LangCollectors .joining (toString (separator ), EMPTY , EMPTY , StringUtils ::toString ));
43234323 }
43244324
43254325 /**
@@ -4556,7 +4556,7 @@ public static String join(final Object[] array, final char delimiter, final int
45564556 * @return the joined String, {@code null} if null array input
45574557 */
45584558 public static String join (final Object [] array , final String delimiter ) {
4559- return array != null ? join (array , toStringOrEmpty (delimiter ), 0 , array .length ) : null ;
4559+ return array != null ? join (array , toString (delimiter ), 0 , array .length ) : null ;
45604560 }
45614561
45624562 /**
@@ -4596,7 +4596,7 @@ public static String join(final Object[] array, final String delimiter) {
45964596 */
45974597 public static String join (final Object [] array , final String delimiter , final int startIndex , final int endIndex ) {
45984598 return array != null ? Streams .of (array ).skip (startIndex ).limit (Math .max (0 , endIndex - startIndex ))
4599- .collect (LangCollectors .joining (delimiter , EMPTY , EMPTY , StringUtils ::toStringOrEmpty )) : null ;
4599+ .collect (LangCollectors .joining (delimiter , EMPTY , EMPTY , StringUtils ::toString )) : null ;
46004600 }
46014601
46024602 /**
@@ -6048,16 +6048,16 @@ public static String removeStartIgnoreCase(final String str, final String remove
60486048 * consider using {@link #repeat(String, int)} instead.
60496049 * </p>
60506050 *
6051- * @param ch character to repeat
6052- * @param repeat number of times to repeat char, negative treated as zero
6051+ * @param repeat character to repeat
6052+ * @param count number of times to repeat char, negative treated as zero
60536053 * @return String with repeated character
60546054 * @see #repeat(String, int)
60556055 */
6056- public static String repeat (final char ch , final int repeat ) {
6057- if (repeat <= 0 ) {
6056+ public static String repeat (final char repeat , final int count ) {
6057+ if (count <= 0 ) {
60586058 return EMPTY ;
60596059 }
6060- return new String (ArrayFill .fill (new char [repeat ], ch ));
6060+ return new String (ArrayFill .fill (new char [count ], repeat ));
60616061 }
60626062
60636063 /**
@@ -6073,44 +6073,44 @@ public static String repeat(final char ch, final int repeat) {
60736073 * StringUtils.repeat("a", -2) = ""
60746074 * </pre>
60756075 *
6076- * @param str the String to repeat, may be null
6077- * @param repeat number of times to repeat str, negative treated as zero
6076+ * @param repeat the String to repeat, may be null
6077+ * @param count number of times to repeat str, negative treated as zero
60786078 * @return a new String consisting of the original String repeated,
60796079 * {@code null} if null String input
60806080 */
6081- public static String repeat (final String str , final int repeat ) {
6081+ public static String repeat (final String repeat , final int count ) {
60826082 // Performance tuned for 2.0 (JDK1.4)
6083- if (str == null ) {
6083+ if (repeat == null ) {
60846084 return null ;
60856085 }
6086- if (repeat <= 0 ) {
6086+ if (count <= 0 ) {
60876087 return EMPTY ;
60886088 }
6089- final int inputLength = str .length ();
6090- if (repeat == 1 || inputLength == 0 ) {
6091- return str ;
6089+ final int inputLength = repeat .length ();
6090+ if (count == 1 || inputLength == 0 ) {
6091+ return repeat ;
60926092 }
6093- if (inputLength == 1 && repeat <= PAD_LIMIT ) {
6094- return repeat (str .charAt (0 ), repeat );
6093+ if (inputLength == 1 && count <= PAD_LIMIT ) {
6094+ return repeat (repeat .charAt (0 ), count );
60956095 }
60966096
6097- final int outputLength = inputLength * repeat ;
6097+ final int outputLength = inputLength * count ;
60986098 switch (inputLength ) {
60996099 case 1 :
6100- return repeat (str .charAt (0 ), repeat );
6100+ return repeat (repeat .charAt (0 ), count );
61016101 case 2 :
6102- final char ch0 = str .charAt (0 );
6103- final char ch1 = str .charAt (1 );
6102+ final char ch0 = repeat .charAt (0 );
6103+ final char ch1 = repeat .charAt (1 );
61046104 final char [] output2 = new char [outputLength ];
6105- for (int i = repeat * 2 - 2 ; i >= 0 ; i --, i --) {
6105+ for (int i = count * 2 - 2 ; i >= 0 ; i --, i --) {
61066106 output2 [i ] = ch0 ;
61076107 output2 [i + 1 ] = ch1 ;
61086108 }
61096109 return new String (output2 );
61106110 default :
61116111 final StringBuilder buf = new StringBuilder (outputLength );
6112- for (int i = 0 ; i < repeat ; i ++) {
6113- buf .append (str );
6112+ for (int i = 0 ; i < count ; i ++) {
6113+ buf .append (repeat );
61146114 }
61156115 return buf .toString ();
61166116 }
@@ -6129,19 +6129,19 @@ public static String repeat(final String str, final int repeat) {
61296129 * StringUtils.repeat("?", ", ", 3) = "?, ?, ?"
61306130 * </pre>
61316131 *
6132- * @param str the String to repeat, may be null
6132+ * @param repeat the String to repeat, may be null
61336133 * @param separator the String to inject, may be null
6134- * @param repeat number of times to repeat str, negative treated as zero
6134+ * @param count number of times to repeat str, negative treated as zero
61356135 * @return a new String consisting of the original String repeated,
61366136 * {@code null} if null String input
61376137 * @since 2.5
61386138 */
6139- public static String repeat (final String str , final String separator , final int repeat ) {
6140- if (str == null || separator == null ) {
6141- return repeat (str , repeat );
6139+ public static String repeat (final String repeat , final String separator , final int count ) {
6140+ if (repeat == null || separator == null ) {
6141+ return repeat (repeat , count );
61426142 }
61436143 // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
6144- final String result = repeat (str + separator , repeat );
6144+ final String result = repeat (repeat + separator , count );
61456145 return Strings .CS .removeEnd (result , separator );
61466146 }
61476147
@@ -6329,9 +6329,7 @@ public static String replaceChars(final String str, final String searchChars, St
63296329 if (isEmpty (str ) || isEmpty (searchChars )) {
63306330 return str ;
63316331 }
6332- if (replaceChars == null ) {
6333- replaceChars = EMPTY ;
6334- }
6332+ replaceChars = toString (replaceChars );
63356333 boolean modified = false ;
63366334 final int replaceCharsLength = replaceChars .length ();
63376335 final int strLength = str .length ();
@@ -8782,7 +8780,14 @@ public static String toString(final byte[] bytes, final String charsetName) {
87828780 return new String (bytes , Charsets .toCharset (charsetName ));
87838781 }
87848782
8785- private static String toStringOrEmpty (final Object obj ) {
8783+ /**
8784+ * Returns the result of calling {@code toString} on the first argument if the first argument is not {@code null} and returns the empty String otherwise.
8785+ *
8786+ * @param o an object
8787+ * @return the result of calling {@code toString} on the first argument if it is not {@code null} and the empty String otherwise.
8788+ * @see Objects#toString(Object)
8789+ */
8790+ private static String toString (final Object obj ) {
87868791 return Objects .toString (obj , EMPTY );
87878792 }
87888793
0 commit comments