This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 67642f0ea2292f75140cf4bf9f4bb27124c98413
Author: Andrus Adamchik <[email protected]>
AuthorDate: Sat May 23 18:27:06 2026 -0400

    Cleanup:  Util.toMap() is deprecated in favor of plain Java alternatives
---
 .../java/org/apache/cayenne/gen/ImportUtils.java   | 11 +++++++---
 .../main/java/org/apache/cayenne/util/Util.java    | 24 ++++++++++++----------
 .../java/org/apache/cayenne/util/UtilTest.java     |  1 +
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ImportUtils.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ImportUtils.java
index 938b1fc15..42fe98818 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ImportUtils.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ImportUtils.java
@@ -23,12 +23,13 @@ import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.EmbeddableAttribute;
 import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.util.Util;
 
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * Methods for mangling strings.
@@ -44,8 +45,12 @@ public class ImportUtils {
                        Byte.class.getName(), Boolean.class.getName(), 
Float.class.getName(), Short.class.getName(),
                        Integer.class.getName(), Character.class.getName() };
 
-       static Map<String, String> classesForPrimitives = 
Util.toMap(primitives, primitiveClasses);
-       static Map<String, String> primitivesForClasses = 
Util.toMap(primitiveClasses, primitives);
+       static final Map<String, String> classesForPrimitives = 
IntStream.range(0, primitives.length)
+                       .boxed()
+                       .collect(Collectors.toUnmodifiableMap(i -> 
primitives[i], i -> primitiveClasses[i]));
+       static final Map<String, String> primitivesForClasses = 
IntStream.range(0, primitiveClasses.length)
+                       .boxed()
+                       .collect(Collectors.toUnmodifiableMap(i -> 
primitiveClasses[i], i -> primitives[i]));
 
        protected Map<String, String> importTypesMap = new HashMap<>();
 
diff --git a/cayenne/src/main/java/org/apache/cayenne/util/Util.java 
b/cayenne/src/main/java/org/apache/cayenne/util/Util.java
index 7ff057a54..95273341b 100644
--- a/cayenne/src/main/java/org/apache/cayenne/util/Util.java
+++ b/cayenne/src/main/java/org/apache/cayenne/util/Util.java
@@ -81,7 +81,7 @@ public class Util {
     }
 
     @Deprecated
-    private static DefaultAdhocObjectFactory objectFactory;
+    private static final DefaultAdhocObjectFactory objectFactory;
 
     static {
         objectFactory = new DefaultAdhocObjectFactory(null, new 
DefaultClassLoaderManager());
@@ -109,7 +109,7 @@ public class Util {
      * separator.
      */
     public static String stringFromFile(File file) throws IOException {
-        return stringFromFile(file, System.getProperty("line.separator"));
+        return stringFromFile(file, System.lineSeparator());
     }
 
     /**
@@ -119,8 +119,8 @@ public class Util {
     public static String stringFromFile(File file, String joinWith) throws 
IOException {
         StringBuilder buf = new StringBuilder();
 
-        try (BufferedReader in = new BufferedReader(new FileReader(file));) {
-            String line = null;
+        try (BufferedReader in = new BufferedReader(new FileReader(file))) {
+            String line;
             while ((line = in.readLine()) != null) {
                 buf.append(line).append(joinWith);
             }
@@ -148,7 +148,7 @@ public class Util {
         StringBuilder builder = new StringBuilder();
 
         for (Object o : objects) {
-            if (builder.length() > 0) {
+            if (!builder.isEmpty()) {
                 builder.append(separator);
             }
 
@@ -173,8 +173,7 @@ public class Util {
      * recursively "unwraps" it, and returns the result to the user.
      */
     public static Throwable unwindException(Throwable th) {
-        if (th instanceof SAXException) {
-            SAXException sax = (SAXException) th;
+        if (th instanceof SAXException sax) {
             if (sax.getException() != null) {
                 return unwindException(sax.getException());
             }
@@ -226,7 +225,7 @@ public class Util {
      * Returns true, if the String is null or an empty string.
      */
     public static boolean isEmptyString(CharSequence string) {
-        return string == null || string.length() == 0;
+        return string == null || string.isEmpty();
     }
 
     /**
@@ -291,7 +290,7 @@ public class Util {
      * @since 4.1
      */
     public static String capitalized(String name) {
-        if (name == null || name.length() == 0) {
+        if (name == null || name.isEmpty()) {
             return name;
         }
 
@@ -305,7 +304,7 @@ public class Util {
      * @since 4.2
      */
     public static String uncapitalized(String aString) {
-        if (aString == null || aString.length() == 0) {
+        if (aString == null || aString.isEmpty()) {
             return aString;
         }
 
@@ -402,7 +401,7 @@ public class Util {
      * @since 3.0
      */
     public static String stripPackageName(String className) {
-        if (className == null || className.length() == 0) {
+        if (className == null || className.isEmpty()) {
             return className;
         }
 
@@ -419,7 +418,10 @@ public class Util {
      * Creates a mutable map out of two arrays with keys and values.
      *
      * @since 1.2
+     * @deprecated use {@link java.util.stream.IntStream#range} with
+     *             {@link java.util.stream.Collectors#toMap} to build a map 
from parallel arrays
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public static <K, V> Map<K, V> toMap(K[] keys, V[] values) {
         int keysSize = (keys != null) ? keys.length : 0;
         int valuesSize = (values != null) ? values.length : 0;
diff --git a/cayenne/src/test/java/org/apache/cayenne/util/UtilTest.java 
b/cayenne/src/test/java/org/apache/cayenne/util/UtilTest.java
index b74086992..7a114681e 100644
--- a/cayenne/src/test/java/org/apache/cayenne/util/UtilTest.java
+++ b/cayenne/src/test/java/org/apache/cayenne/util/UtilTest.java
@@ -75,6 +75,7 @@ public class UtilTest {
        }
 
        @Test
+       @SuppressWarnings("deprecation")
        public void toMap() {
                Object[] keys = new Object[] { "a", "b" };
                Object[] values = new Object[] { "1", "2" };

Reply via email to