@@ -25,10 +25,10 @@ public static String repeat(@NotNull CharSequence charSequence, int amount) {
25
25
}
26
26
27
27
/**
28
- * Formats a {@link Double } value using the given pattern
28
+ * Formats a {@link Number } value using the given pattern
29
29
*
30
30
* @param value the {@link Number} to format
31
- * @param pattern the pattern to use
31
+ * @param pattern the pattern to use (if null: {@code #,###.##})
32
32
*
33
33
* @return the formatted value
34
34
*/
@@ -39,15 +39,28 @@ public static String formatNumber(@NotNull Number value, @Nullable String patter
39
39
}
40
40
41
41
/**
42
- * Shortens a string to a given length, adding "..." at the end ("..." is included in the length)
42
+ * Formats a {@link Number} value using {@code #,###.##}
43
+ *
44
+ * @param value the {@link Number} to format
45
+ *
46
+ * @return the formatted value
47
+ */
48
+ @ NotNull
49
+ public static String formatNumber (@ NotNull Number value ) {
50
+ return formatNumber (value , null );
51
+ }
52
+
53
+ /**
54
+ * Shortens a string to a given length, adding {@code ...} at the end (included in the length)
43
55
*
44
56
* @param string the string to shorten
45
57
* @param length the length to shorten to
46
58
*
47
- * @return the shortened string
59
+ * @return the shortened string with {@code ...} at the end
48
60
*/
49
61
@ NotNull
50
62
public static String shorten (@ NotNull String string , int length ) {
63
+ if (length < 3 ) throw new IllegalArgumentException ("Length must be at least 3" );
51
64
return string .length () + 3 > length ? string .substring (0 , length - 3 ) + "..." : string ;
52
65
}
53
66
0 commit comments