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

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

commit 26bd84e32c73007350dfb3482b41f7ce2917e3b3
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jul 10 09:37:38 2026 -0400

    Internal refactoring for duplication.
---
 .../compress/harmony/unpack200/BandSet.java        | 35 +++++++++-------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
index aa75dbf00..1b7436948 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
@@ -47,6 +47,17 @@
  */
 public abstract class BandSet {
 
+    static int sumPositive(final int[] counts) throws Pack200Exception {
+        int totalCount = 0;
+        for (final int count : counts) {
+            if (count < 0) {
+                throw new Pack200Exception("count < 0");
+            }
+            totalCount += count;
+        }
+        return totalCount;
+    }
+
     /**
      * Segment.
      */
@@ -149,13 +160,7 @@ public int[] decodeBandInt(final String name, final 
InputStream in, final BHSDCo
     public int[][] decodeBandInt(final String name, final InputStream in, 
final BHSDCodec defaultCodec, final int[] counts)
             throws IOException, Pack200Exception {
         final int[][] result = new int[counts.length][];
-        int totalCount = 0;
-        for (final int count : counts) {
-            if (count < 0) {
-                throw new Pack200Exception("count < 0");
-            }
-            totalCount += count;
-        }
+        final int totalCount = sumPositive(counts);
         final int[] twoDResult = decodeBandInt(name, in, defaultCodec, 
totalCount);
         int index = 0;
         for (int i = 0; i < result.length; i++) {
@@ -549,13 +554,7 @@ public long[][] parseFlags(final String name, final 
InputStream in, final int[]
         if (count == 0) {
             return new long[][] { {} };
         }
-        int sum = 0;
-        for (int i = 0; i < count; i++) {
-            if (counts[i] < 0) {
-                throw new Pack200Exception("count < 0");
-            }
-            sum += counts[i];
-        }
+        final int sum = sumPositive(counts);
         int[] hi = null;
         final int[] lo;
         if (hiCodec != null) {
@@ -633,13 +632,7 @@ public String[][] parseReferences(final String name, final 
InputStream in, final
         if (count == 0) {
             return new String[][] { {} };
         }
-        int sum = 0;
-        for (int i = 0; i < count; i++) {
-            if (counts[i] < 0) {
-                throw new Pack200Exception("count < 0");
-            }
-            sum += counts[i];
-        }
+        final int sum = sumPositive(counts);
         // TODO Merge the decode and parsing of a multiple structure into one
         final int[] indices = decodeBandInt(name, in, codec, sum);
         final String[] result1 = new String[sum];

Reply via email to