@@ -81,7 +81,7 @@ public class Util {
8181 }
8282
8383 @ Deprecated
84- private static DefaultAdhocObjectFactory objectFactory ;
84+ private static final DefaultAdhocObjectFactory objectFactory ;
8585
8686 static {
8787 objectFactory = new DefaultAdhocObjectFactory (null , new DefaultClassLoaderManager ());
@@ -109,7 +109,7 @@ public static File toFile(URL url) throws IllegalArgumentException {
109109 * separator.
110110 */
111111 public static String stringFromFile (File file ) throws IOException {
112- return stringFromFile (file , System .getProperty ( "line.separator" ));
112+ return stringFromFile (file , System .lineSeparator ( ));
113113 }
114114
115115 /**
@@ -119,8 +119,8 @@ public static String stringFromFile(File file) throws IOException {
119119 public static String stringFromFile (File file , String joinWith ) throws IOException {
120120 StringBuilder buf = new StringBuilder ();
121121
122- try (BufferedReader in = new BufferedReader (new FileReader (file )); ) {
123- String line = null ;
122+ try (BufferedReader in = new BufferedReader (new FileReader (file ))) {
123+ String line ;
124124 while ((line = in .readLine ()) != null ) {
125125 buf .append (line ).append (joinWith );
126126 }
@@ -148,7 +148,7 @@ public static String join(Iterable<?> objects, String separator) {
148148 StringBuilder builder = new StringBuilder ();
149149
150150 for (Object o : objects ) {
151- if (builder .length () > 0 ) {
151+ if (! builder .isEmpty () ) {
152152 builder .append (separator );
153153 }
154154
@@ -173,8 +173,7 @@ public static String substBackslashes(String string) {
173173 * recursively "unwraps" it, and returns the result to the user.
174174 */
175175 public static Throwable unwindException (Throwable th ) {
176- if (th instanceof SAXException ) {
177- SAXException sax = (SAXException ) th ;
176+ if (th instanceof SAXException sax ) {
178177 if (sax .getException () != null ) {
179178 return unwindException (sax .getException ());
180179 }
@@ -226,7 +225,7 @@ public static <T> int nullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2
226225 * Returns true, if the String is null or an empty string.
227226 */
228227 public static boolean isEmptyString (CharSequence string ) {
229- return string == null || string .length () == 0 ;
228+ return string == null || string .isEmpty () ;
230229 }
231230
232231 /**
@@ -291,7 +290,7 @@ public static int countMatches(final String str, final String sub) {
291290 * @since 4.1
292291 */
293292 public static String capitalized (String name ) {
294- if (name == null || name .length () == 0 ) {
293+ if (name == null || name .isEmpty () ) {
295294 return name ;
296295 }
297296
@@ -305,7 +304,7 @@ public static String capitalized(String name) {
305304 * @since 4.2
306305 */
307306 public static String uncapitalized (String aString ) {
308- if (aString == null || aString .length () == 0 ) {
307+ if (aString == null || aString .isEmpty () ) {
309308 return aString ;
310309 }
311310
@@ -402,7 +401,7 @@ public static String getPackagePath(String className) {
402401 * @since 3.0
403402 */
404403 public static String stripPackageName (String className ) {
405- if (className == null || className .length () == 0 ) {
404+ if (className == null || className .isEmpty () ) {
406405 return className ;
407406 }
408407
@@ -419,7 +418,10 @@ public static String stripPackageName(String className) {
419418 * Creates a mutable map out of two arrays with keys and values.
420419 *
421420 * @since 1.2
421+ * @deprecated use {@link java.util.stream.IntStream#range} with
422+ * {@link java.util.stream.Collectors#toMap} to build a map from parallel arrays
422423 */
424+ @ Deprecated (since = "5.0" , forRemoval = true )
423425 public static <K , V > Map <K , V > toMap (K [] keys , V [] values ) {
424426 int keysSize = (keys != null ) ? keys .length : 0 ;
425427 int valuesSize = (values != null ) ? values .length : 0 ;
0 commit comments