@@ -55,10 +55,9 @@ private StringUtils() {
5555 * Gets a CharSequence length or {@code 0} if the CharSequence is
5656 * {@code null}.
5757 *
58- * @param cs
59- * a CharSequence or {@code null}
58+ * @param cs a CharSequence or {@code null}
6059 * @return CharSequence length or {@code 0} if the CharSequence is
61- * {@code null}.
60+ * {@code null}.
6261 */
6362 public static int length (final CharSequence cs ) {
6463 return cs == null ? 0 : cs .length ();
@@ -77,10 +76,10 @@ public static int length(final CharSequence cs) {
7776 * StringUtils.repeat("a", -2) = ""
7877 * </pre>
7978 *
80- * @param str the String to repeat, may be null
81- * @param repeat number of times to repeat str, negative treated as zero
79+ * @param str the String to repeat, may be null
80+ * @param repeat number of times to repeat str, negative treated as zero
8281 * @return a new String consisting of the original String repeated,
83- * {@code null} if null String input
82+ * {@code null} if null String input
8483 */
8584 public static String repeat (final String str , final int repeat ) {
8685 // Performance tuned for 2.0 (JDK1.4)
@@ -101,9 +100,9 @@ public static String repeat(final String str, final int repeat) {
101100
102101 final int outputLength = inputLength * repeat ;
103102 switch (inputLength ) {
104- case 1 :
103+ case 1 :
105104 return repeat (str .charAt (0 ), repeat );
106- case 2 :
105+ case 2 :
107106 final char ch0 = str .charAt (0 );
108107 final char ch1 = str .charAt (1 );
109108 final char [] output2 = new char [outputLength ];
@@ -112,7 +111,7 @@ public static String repeat(final String str, final int repeat) {
112111 output2 [i + 1 ] = ch1 ;
113112 }
114113 return new String (output2 );
115- default :
114+ default :
116115 final StringBuilder buf = new StringBuilder (outputLength );
117116 for (int i = 0 ; i < repeat ; i ++) {
118117 buf .append (str );
@@ -134,15 +133,15 @@ public static String repeat(final String str, final int repeat) {
134133 * StringUtils.repeat("?", ", ", 3) = "?, ?, ?"
135134 * </pre>
136135 *
137- * @param str the String to repeat, may be null
138- * @param separator the String to inject, may be null
139- * @param repeat number of times to repeat str, negative treated as zero
136+ * @param str the String to repeat, may be null
137+ * @param separator the String to inject, may be null
138+ * @param repeat number of times to repeat str, negative treated as zero
140139 * @return a new String consisting of the original String repeated,
141- * {@code null} if null String input
140+ * {@code null} if null String input
142141 * @since 2.5
143142 */
144143 public static String repeat (final String str , final String separator , final int repeat ) {
145- if (str == null || separator == null ) {
144+ if (str == null || separator == null ) {
146145 return repeat (str , repeat );
147146 }
148147 // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
@@ -168,10 +167,10 @@ public static String repeat(final String str, final String separator, final int
168167 * StringUtils.removeEnd("abc", "") = "abc"
169168 * </pre>
170169 *
171- * @param str the source String to search, may be null
172- * @param remove the String to search for and remove, may be null
170+ * @param str the source String to search, may be null
171+ * @param remove the String to search for and remove, may be null
173172 * @return the substring with the string removed if found,
174- * {@code null} if null String input
173+ * {@code null} if null String input
175174 */
176175 public static String removeEnd (final String str , final String remove ) {
177176 if (isAnyEmpty (str , remove )) {
@@ -200,8 +199,8 @@ public static String removeEnd(final String str, final String remove) {
200199 * consider using {@link #repeat(String, int)} instead.
201200 * </p>
202201 *
203- * @param ch character to repeat
204- * @param repeat number of times to repeat char, negative treated as zero
202+ * @param ch character to repeat
203+ * @param repeat number of times to repeat char, negative treated as zero
205204 * @return String with repeated character
206205 * @see #repeat(String, int)
207206 */
@@ -234,8 +233,8 @@ public static String repeat(final char ch, final int repeat) {
234233 * StringUtils.stripEnd("120.00", ".0") = "12"
235234 * </pre>
236235 *
237- * @param str the String to remove characters from, may be null
238- * @param stripChars the set of characters to remove, null treated as whitespace
236+ * @param str the String to remove characters from, may be null
237+ * @param stripChars the set of characters to remove, null treated as whitespace
239238 * @return the stripped String, {@code null} if null String input
240239 */
241240 public static String stripEnd (final String str , final String stripChars ) {
@@ -274,12 +273,12 @@ public static String stripEnd(final String str, final String stripChars) {
274273 * StringUtils.replace("aba", "a", "z") = "zbz"
275274 * </pre>
276275 *
277- * @see #replace(String text, String searchString, String replacement, int max)
278- * @param text text to search and replace in, may be null
279- * @param searchString the String to search for, may be null
276+ * @param text text to search and replace in, may be null
277+ * @param searchString the String to search for, may be null
280278 * @param replacement the String to replace it with, may be null
281279 * @return the text with any replacements processed,
282- * {@code null} if null String input
280+ * {@code null} if null String input
281+ * @see #replace(String text, String searchString, String replacement, int max)
283282 */
284283 public static String replace (final String text , final String searchString , final String replacement ) {
285284 return replace (text , searchString , replacement , -1 );
@@ -306,12 +305,12 @@ public static String replace(final String text, final String searchString, final
306305 * StringUtils.replace("abaa", "a", "z", -1) = "zbzz"
307306 * </pre>
308307 *
309- * @param text text to search and replace in, may be null
310- * @param searchString the String to search for, may be null
308+ * @param text text to search and replace in, may be null
309+ * @param searchString the String to search for, may be null
311310 * @param replacement the String to replace it with, may be null
312- * @param max maximum number of values to replace, or {@code -1} if no maximum
311+ * @param max maximum number of values to replace, or {@code -1} if no maximum
313312 * @return the text with any replacements processed,
314- * {@code null} if null String input
313+ * {@code null} if null String input
315314 */
316315 public static String replace (final String text , final String searchString , final String replacement , int max ) {
317316 if (isAnyEmpty (text , searchString ) || replacement == null || max == 0 ) {
@@ -374,7 +373,7 @@ public static boolean isNoneEmpty(final String... ss) {
374373 if (ArrayUtils .isEmpty (ss )) {
375374 return false ;
376375 }
377- for (final String s : ss ){
376+ for (final String s : ss ) {
378377 if (isEmpty (s )) {
379378 return false ;
380379 }
@@ -478,19 +477,28 @@ public static boolean isContains(String[] values, String value) {
478477 return false ;
479478 }
480479
481- public static boolean isNumeric (String str ) {
482- if (str == null ) {
480+ public static boolean isNumeric (String str , boolean allowDot ) {
481+ if (str == null || str . isEmpty () ) {
483482 return false ;
484483 }
484+ boolean hasDot = false ;
485485 int sz = str .length ();
486486 for (int i = 0 ; i < sz ; i ++) {
487+ if (str .charAt (i ) == '.' ) {
488+ if (hasDot || !allowDot ) {
489+ return false ;
490+ }
491+ hasDot = true ;
492+ continue ;
493+ }
487494 if (!Character .isDigit (str .charAt (i ))) {
488495 return false ;
489496 }
490497 }
491498 return true ;
492499 }
493500
501+
494502 /**
495503 * @param e
496504 * @return string
0 commit comments