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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 29c6221b3f932d19166021c30b4bdcd7b1ef0cef
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Sep 2 18:50:29 2024 -0400

    Use Map.compute()
---
 .../commons/compress/harmony/pack200/CpBands.java  | 27 ++++------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/harmony/pack200/CpBands.java 
b/src/main/java/org/apache/commons/compress/harmony/pack200/CpBands.java
index fbf5f769f..40df3bce6 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CpBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CpBands.java
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.function.BiFunction;
 
 import org.objectweb.asm.Type;
 
@@ -106,34 +107,16 @@ public class CpBands extends BandSet {
                 j++;
             }
         }
+        final BiFunction<? super CPClass, ? super Integer, ? extends Integer> 
remappingFunction = (k, v) -> v != null ? v + 1 : 1;
         final Map<CPClass, Integer> classNameToIndex = new HashMap<>();
-        cp_Field.forEach(mOrF -> {
-            final CPClass cpClassName = mOrF.getClassName();
-            final Integer index = classNameToIndex.get(cpClassName);
-            if (index == null) {
-                classNameToIndex.put(cpClassName, Integer.valueOf(1));
-                mOrF.setIndexInClass(0);
-            } else {
-                final int theIndex = index.intValue();
-                mOrF.setIndexInClass(theIndex);
-                classNameToIndex.put(cpClassName, Integer.valueOf(theIndex + 
1));
-            }
-        });
+        cp_Field.forEach(mOrF -> 
mOrF.setIndexInClass(classNameToIndex.compute(mOrF.getClassName(), 
remappingFunction) - 1));
         classNameToIndex.clear();
         final Map<CPClass, Integer> classNameToConstructorIndex = new 
HashMap<>();
         cp_Method.forEach(mOrF -> {
             final CPClass cpClassName = mOrF.getClassName();
-            final Integer index = classNameToIndex.get(cpClassName);
-            if (index == null) {
-                classNameToIndex.put(cpClassName, Integer.valueOf(1));
-                mOrF.setIndexInClass(0);
-            } else {
-                final int theIndex = index.intValue();
-                mOrF.setIndexInClass(theIndex);
-                classNameToIndex.put(cpClassName, Integer.valueOf(theIndex + 
1));
-            }
+            mOrF.setIndexInClass(classNameToIndex.compute(cpClassName, 
remappingFunction) - 1);
             if (mOrF.getDesc().getName().equals("<init>")) {
-                
mOrF.setIndexInClassForConstructor(classNameToConstructorIndex.compute(cpClassName,
 (k, v) -> v != null ? v + 1 : 1) - 1);
+                
mOrF.setIndexInClassForConstructor(classNameToConstructorIndex.compute(cpClassName,
 remappingFunction) - 1);
             }
         });
     }

Reply via email to