You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/09/11 07:39:04 UTC

[GitHub] [commons-numbers] aherbert commented on a diff in pull request #125: NUMBERS-186 added complex non-interleaved list implementation

aherbert commented on code in PR #125:
URL: https://github.com/apache/commons-numbers/pull/125#discussion_r967773595


##########
commons-numbers-complex-arrays/src/test/java/org/apache/commons/numbers/complex/arrays/ComplexListTest.java:
##########
@@ -349,10 +561,14 @@ private static <T> void assertListOperation(Function<List<Complex>, T> operation
         Assertions.assertEquals(l1, l2);
     }
 
-    private static <T> void assertListOperation(Function<List<Complex>, T> operation) {
+    private static <T> void assertListOperation1(Function<List<Complex>, T> operation) {

Review Comment:
   `assertListOperationInterleaved`
   
   Looking at the use cases for this method, I think it could be removed if tests are broken down and parameterized.



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -276,22 +322,11 @@ public static ComplexList from(double[] data) {
      * using instances of Complex.</p>
      *
      * <p>An application can increase the capacity of an ComplexInterleavedList instance before adding a large number of complex numbers
-     * using the ensureCapacity operation. This may reduce the amount of incremental reallocation.</p>
+     * using the ensureCapacityInternal operation. This may reduce the amount of incremental reallocation.</p>
      *
      * <p>This list does not support {@code null} Complex objects.
      */
     private static class ComplexInterleavedList extends ComplexList {
-        /**
-         * The maximum size of array to allocate.
-         * Ensuring max capacity is even with additional space for VM array headers.
-         */
-        private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 9;

Review Comment:
   All of these except the MAX_CAPACITY are specified to this list



##########
commons-numbers-complex-arrays/src/test/java/org/apache/commons/numbers/complex/arrays/ComplexListTest.java:
##########
@@ -118,17 +140,81 @@ void testAddAndAddAll() {
 
         //Test for adding an empty list to an empty list
         ComplexList list = ComplexList.interleaved();
-        assertListOperation(l -> {
+        assertListOperation1(l -> {
+            l.addAll(list);
+            return l.addAll(0, list);
+        });
+    }
+
+    @Test
+    void testAddAndAddAllForComplexNonInterleavedList() {

Review Comment:
   Code duplication of the entire method for a new list is not maintainable. Since the list must pass the same test then you can do this using a parameterized test:
   ```Java
       /**
        * Generate a stream of arguments containing empty {@code Complex<List>} implementations.
        *
        * @return the stream of arguments
        */
       static Stream<Arguments> listImplementations() {
           return Stream.of(Arguments.of(ComplexList.interleaved()),
                            Arguments.of(ComplexList.nonInterleaved()));
       }
   
       @ParameterizedTest
       @MethodSource({"listImplementations"})
       void testAddAndAddAllList(List<Complex> l2) {
           List<Complex> l1 = new ArrayList<>();
           assertListOperation(list -> list.add(Complex.ofCartesian(1, 2)), l1, l2);
           assertListOperation(list -> {
               list.add(1, Complex.ofCartesian(10, 20));
               return Boolean.TRUE;
           }, l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(13, 14)), l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(15, 16)), l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(17, 18)), l1, l2);
           assertListOperation(list -> {
               list.addAll(1, list);
               return Boolean.TRUE;
           }, l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(19, 20)), l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(21, 22)), l1, l2);
           assertListOperation(list -> list.add(Complex.ofCartesian(23, 24)), l1, l2);
       }
   ```
   The test may have to be broken down into smaller tests as the parameter will be an empty list. If you wish to start with a list populated with e.g. 10 random Complex numbers then you can add a second static method to stream arguments with populated lists.
   
   Note: You can create multiple parameters for the parameterized test if these require:
   ```Java
       static Stream<Arguments> listImplementationsWithSize() {
           return Stream.of(Arguments.of(ComplexList.interleaved(), 10),
                            Arguments.of(ComplexList.nonInterleaved(), 10));
       }
   
       @ParameterizedTest
       @MethodSource({"listImplementationsWithSize"})
       void testAddAndAddAllList(List<Complex> l2, int size) {
   ```
   



##########
commons-numbers-complex-arrays/src/test/java/org/apache/commons/numbers/complex/arrays/ComplexListTest.java:
##########
@@ -349,10 +561,14 @@ private static <T> void assertListOperation(Function<List<Complex>, T> operation
         Assertions.assertEquals(l1, l2);
     }
 
-    private static <T> void assertListOperation(Function<List<Complex>, T> operation) {
+    private static <T> void assertListOperation1(Function<List<Complex>, T> operation) {
         assertListOperation(operation, new ArrayList<>(), ComplexList.interleaved());
     }
 
+    private static <T> void assertListOperation2(Function<List<Complex>, T> operation) {

Review Comment:
   `assertListOperationNonInterleaved`
   
   Looking at the use cases for this method, I think it could be removed if tests are broken down and parameterized.



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -37,6 +37,17 @@
  */
 public abstract class ComplexList extends AbstractList<Complex> {
 
+    /**
+     * The maximum size of array to allocate.
+     * Ensuring max capacity is even with additional space for VM array headers.
+     */
+    protected static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 9;

Review Comment:
   These should not be here. The max capacity of the interleaved list is different from the non-interleaved list. Only the DEFAULT_CAPACITY should be shared.



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -566,4 +601,302 @@ public void forEach(ComplexConsumer action) {
             }
         }
     }
+
+    /**
+     * Resizable-double arrays implementation of the List interface. Implements all optional list operations,
+     * and permits all complex numbers. In addition to implementing the List interface,
+     * this class provides methods to manipulate the size of the arrays that are used internally to store the list.
+     *
+     * <p>Each ComplexNonInterleavedList instance has a capacity. The capacity is the size of the double arrays used to store the complex numbers
+     * in the list. As complex numbers are added to an ComplexNonInterleavedList, its capacity grows automatically.
+     * The complex number is stored using an non-interleaved format and so the maximum number of complex numbers that may be added is
+     * approximately 2<sup>30</sup>. This is half the maximum capacity of java.util.ArrayList.
+     * The memory usage is more efficient than using a List of Complex objects as the underlying numbers are not stored
+     * using instances of Complex.</p>
+     *
+     * <p>An application can increase the capacity of an ComplexNonInterleavedList instance before adding a large number of complex numbers
+     * using the ensureCapacityInternal operation. This may reduce the amount of incremental reallocation.</p>
+     *
+     * <p>This list does not support {@code null} Complex objects.
+     */
+    private static class ComplexNonInterleavedList extends ComplexList {
+
+        /**
+         * Storage for the real parts of complex numbers.
+         */
+        private double[] realParts;
+
+        /**
+         * Storage for the imaginary parts of complex numbers.
+         */
+        private double[] imaginaryParts;
+
+        /**
+         * Constructs an empty list which can store up to the specified capacity without a memory reallocation.
+         *
+         * @param capacity Capacity of list.
+         * @throws IllegalArgumentException if the {@code capacity} is greater than {@code MAX_CAPACITY}.
+         */
+        ComplexNonInterleavedList(int capacity) {
+            if (capacity > MAX_CAPACITY) {
+                throw new IllegalArgumentException(String.format(OOM_ERROR_STRING, capacity));
+            }
+            final int arrayLength = Math.max(DEFAULT_CAPACITY, capacity);
+            realParts = new double[arrayLength];
+            imaginaryParts = new double[arrayLength];
+        }
+
+        /**
+         * Constructs an empty list.
+         */
+        ComplexNonInterleavedList() {
+            realParts = new double[DEFAULT_CAPACITY];
+            imaginaryParts = new double[DEFAULT_CAPACITY];
+        }
+
+        /**
+         * Constructs a non-interleaved list using the specified double arrays.
+         * The data isn't defensively copied, the specified arrays is used in-place.
+         *
+         * @param fromReal Specified backing double array for real parts.
+         * @param fromImaginary Specified backing double array for imaginary parts.
+         * @throws IllegalArgumentException if the specified double arrays don't have the same amount of doubles.
+         */
+        ComplexNonInterleavedList(double[] fromReal, double[] fromImaginary) {
+            if (fromReal.length != fromImaginary.length) {
+                throw new IllegalArgumentException("Need the same amount of real and imaginary parts");
+            }
+            realParts = fromReal;
+            imaginaryParts = fromImaginary;
+            size = fromReal.length;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex get(int index) {
+            rangeCheck(index);
+            return Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getReal(int index) {
+            rangeCheck(index);
+            return realParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getImaginary(int index) {
+            rangeCheck(index);
+            return imaginaryParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex set(int index, Complex number) {
+            rangeCheck(index);
+            final Complex oldValue = Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+            realParts[index] = number.getReal();
+            imaginaryParts[index] = number.getImaginary();
+            return oldValue;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setReal(int index, double real) {
+            rangeCheck(index);
+            realParts[index] = real;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setImaginary(int index, double imaginary) {
+            rangeCheck(index);
+            imaginaryParts[index] = imaginary;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        double[] toArrayReal() {
+            final int length = size;

Review Comment:
   return Arrays.copyOf(realParts, size);



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -566,4 +601,302 @@ public void forEach(ComplexConsumer action) {
             }
         }
     }
+
+    /**
+     * Resizable-double arrays implementation of the List interface. Implements all optional list operations,
+     * and permits all complex numbers. In addition to implementing the List interface,
+     * this class provides methods to manipulate the size of the arrays that are used internally to store the list.
+     *
+     * <p>Each ComplexNonInterleavedList instance has a capacity. The capacity is the size of the double arrays used to store the complex numbers
+     * in the list. As complex numbers are added to an ComplexNonInterleavedList, its capacity grows automatically.
+     * The complex number is stored using an non-interleaved format and so the maximum number of complex numbers that may be added is
+     * approximately 2<sup>30</sup>. This is half the maximum capacity of java.util.ArrayList.

Review Comment:
   2<sup>31</sup>, the same capacity as ArrayList



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -566,4 +601,302 @@ public void forEach(ComplexConsumer action) {
             }
         }
     }
+
+    /**
+     * Resizable-double arrays implementation of the List interface. Implements all optional list operations,
+     * and permits all complex numbers. In addition to implementing the List interface,
+     * this class provides methods to manipulate the size of the arrays that are used internally to store the list.
+     *
+     * <p>Each ComplexNonInterleavedList instance has a capacity. The capacity is the size of the double arrays used to store the complex numbers
+     * in the list. As complex numbers are added to an ComplexNonInterleavedList, its capacity grows automatically.
+     * The complex number is stored using an non-interleaved format and so the maximum number of complex numbers that may be added is
+     * approximately 2<sup>30</sup>. This is half the maximum capacity of java.util.ArrayList.
+     * The memory usage is more efficient than using a List of Complex objects as the underlying numbers are not stored
+     * using instances of Complex.</p>
+     *
+     * <p>An application can increase the capacity of an ComplexNonInterleavedList instance before adding a large number of complex numbers
+     * using the ensureCapacityInternal operation. This may reduce the amount of incremental reallocation.</p>
+     *
+     * <p>This list does not support {@code null} Complex objects.
+     */
+    private static class ComplexNonInterleavedList extends ComplexList {
+
+        /**
+         * Storage for the real parts of complex numbers.
+         */
+        private double[] realParts;
+
+        /**
+         * Storage for the imaginary parts of complex numbers.
+         */
+        private double[] imaginaryParts;
+
+        /**
+         * Constructs an empty list which can store up to the specified capacity without a memory reallocation.
+         *
+         * @param capacity Capacity of list.
+         * @throws IllegalArgumentException if the {@code capacity} is greater than {@code MAX_CAPACITY}.
+         */
+        ComplexNonInterleavedList(int capacity) {
+            if (capacity > MAX_CAPACITY) {
+                throw new IllegalArgumentException(String.format(OOM_ERROR_STRING, capacity));
+            }
+            final int arrayLength = Math.max(DEFAULT_CAPACITY, capacity);
+            realParts = new double[arrayLength];
+            imaginaryParts = new double[arrayLength];
+        }
+
+        /**
+         * Constructs an empty list.
+         */
+        ComplexNonInterleavedList() {
+            realParts = new double[DEFAULT_CAPACITY];
+            imaginaryParts = new double[DEFAULT_CAPACITY];
+        }
+
+        /**
+         * Constructs a non-interleaved list using the specified double arrays.
+         * The data isn't defensively copied, the specified arrays is used in-place.
+         *
+         * @param fromReal Specified backing double array for real parts.
+         * @param fromImaginary Specified backing double array for imaginary parts.
+         * @throws IllegalArgumentException if the specified double arrays don't have the same amount of doubles.

Review Comment:
   Also throws a NullPointerException ...



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -566,4 +601,302 @@ public void forEach(ComplexConsumer action) {
             }
         }
     }
+
+    /**
+     * Resizable-double arrays implementation of the List interface. Implements all optional list operations,
+     * and permits all complex numbers. In addition to implementing the List interface,
+     * this class provides methods to manipulate the size of the arrays that are used internally to store the list.
+     *
+     * <p>Each ComplexNonInterleavedList instance has a capacity. The capacity is the size of the double arrays used to store the complex numbers
+     * in the list. As complex numbers are added to an ComplexNonInterleavedList, its capacity grows automatically.
+     * The complex number is stored using an non-interleaved format and so the maximum number of complex numbers that may be added is
+     * approximately 2<sup>30</sup>. This is half the maximum capacity of java.util.ArrayList.
+     * The memory usage is more efficient than using a List of Complex objects as the underlying numbers are not stored
+     * using instances of Complex.</p>
+     *
+     * <p>An application can increase the capacity of an ComplexNonInterleavedList instance before adding a large number of complex numbers
+     * using the ensureCapacityInternal operation. This may reduce the amount of incremental reallocation.</p>
+     *
+     * <p>This list does not support {@code null} Complex objects.
+     */
+    private static class ComplexNonInterleavedList extends ComplexList {
+
+        /**
+         * Storage for the real parts of complex numbers.
+         */
+        private double[] realParts;
+
+        /**
+         * Storage for the imaginary parts of complex numbers.
+         */
+        private double[] imaginaryParts;
+
+        /**
+         * Constructs an empty list which can store up to the specified capacity without a memory reallocation.
+         *
+         * @param capacity Capacity of list.
+         * @throws IllegalArgumentException if the {@code capacity} is greater than {@code MAX_CAPACITY}.
+         */
+        ComplexNonInterleavedList(int capacity) {
+            if (capacity > MAX_CAPACITY) {
+                throw new IllegalArgumentException(String.format(OOM_ERROR_STRING, capacity));
+            }
+            final int arrayLength = Math.max(DEFAULT_CAPACITY, capacity);
+            realParts = new double[arrayLength];
+            imaginaryParts = new double[arrayLength];
+        }
+
+        /**
+         * Constructs an empty list.
+         */
+        ComplexNonInterleavedList() {
+            realParts = new double[DEFAULT_CAPACITY];
+            imaginaryParts = new double[DEFAULT_CAPACITY];
+        }
+
+        /**
+         * Constructs a non-interleaved list using the specified double arrays.
+         * The data isn't defensively copied, the specified arrays is used in-place.
+         *
+         * @param fromReal Specified backing double array for real parts.
+         * @param fromImaginary Specified backing double array for imaginary parts.
+         * @throws IllegalArgumentException if the specified double arrays don't have the same amount of doubles.
+         */
+        ComplexNonInterleavedList(double[] fromReal, double[] fromImaginary) {
+            if (fromReal.length != fromImaginary.length) {
+                throw new IllegalArgumentException("Need the same amount of real and imaginary parts");
+            }
+            realParts = fromReal;
+            imaginaryParts = fromImaginary;
+            size = fromReal.length;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex get(int index) {
+            rangeCheck(index);
+            return Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getReal(int index) {
+            rangeCheck(index);
+            return realParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getImaginary(int index) {
+            rangeCheck(index);
+            return imaginaryParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex set(int index, Complex number) {
+            rangeCheck(index);
+            final Complex oldValue = Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+            realParts[index] = number.getReal();
+            imaginaryParts[index] = number.getImaginary();
+            return oldValue;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setReal(int index, double real) {
+            rangeCheck(index);
+            realParts[index] = real;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setImaginary(int index, double imaginary) {
+            rangeCheck(index);
+            imaginaryParts[index] = imaginary;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        double[] toArrayReal() {
+            final int length = size;
+            final double[] real = new double[length];
+            System.arraycopy(realParts, 0, real, 0, length);
+            return real;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        double[] toArrayImaginary() {
+            final int length = size;

Review Comment:
   return Arrays.copyOf(imaginaryParts, size);



##########
commons-numbers-complex-arrays/src/main/java/org/apache/commons/numbers/complex/arrays/ComplexList.java:
##########
@@ -566,4 +601,302 @@ public void forEach(ComplexConsumer action) {
             }
         }
     }
+
+    /**
+     * Resizable-double arrays implementation of the List interface. Implements all optional list operations,
+     * and permits all complex numbers. In addition to implementing the List interface,
+     * this class provides methods to manipulate the size of the arrays that are used internally to store the list.
+     *
+     * <p>Each ComplexNonInterleavedList instance has a capacity. The capacity is the size of the double arrays used to store the complex numbers
+     * in the list. As complex numbers are added to an ComplexNonInterleavedList, its capacity grows automatically.
+     * The complex number is stored using an non-interleaved format and so the maximum number of complex numbers that may be added is
+     * approximately 2<sup>30</sup>. This is half the maximum capacity of java.util.ArrayList.
+     * The memory usage is more efficient than using a List of Complex objects as the underlying numbers are not stored
+     * using instances of Complex.</p>
+     *
+     * <p>An application can increase the capacity of an ComplexNonInterleavedList instance before adding a large number of complex numbers
+     * using the ensureCapacityInternal operation. This may reduce the amount of incremental reallocation.</p>
+     *
+     * <p>This list does not support {@code null} Complex objects.
+     */
+    private static class ComplexNonInterleavedList extends ComplexList {
+
+        /**
+         * Storage for the real parts of complex numbers.
+         */
+        private double[] realParts;
+
+        /**
+         * Storage for the imaginary parts of complex numbers.
+         */
+        private double[] imaginaryParts;
+
+        /**
+         * Constructs an empty list which can store up to the specified capacity without a memory reallocation.
+         *
+         * @param capacity Capacity of list.
+         * @throws IllegalArgumentException if the {@code capacity} is greater than {@code MAX_CAPACITY}.
+         */
+        ComplexNonInterleavedList(int capacity) {
+            if (capacity > MAX_CAPACITY) {
+                throw new IllegalArgumentException(String.format(OOM_ERROR_STRING, capacity));
+            }
+            final int arrayLength = Math.max(DEFAULT_CAPACITY, capacity);
+            realParts = new double[arrayLength];
+            imaginaryParts = new double[arrayLength];
+        }
+
+        /**
+         * Constructs an empty list.
+         */
+        ComplexNonInterleavedList() {
+            realParts = new double[DEFAULT_CAPACITY];
+            imaginaryParts = new double[DEFAULT_CAPACITY];
+        }
+
+        /**
+         * Constructs a non-interleaved list using the specified double arrays.
+         * The data isn't defensively copied, the specified arrays is used in-place.
+         *
+         * @param fromReal Specified backing double array for real parts.
+         * @param fromImaginary Specified backing double array for imaginary parts.
+         * @throws IllegalArgumentException if the specified double arrays don't have the same amount of doubles.
+         */
+        ComplexNonInterleavedList(double[] fromReal, double[] fromImaginary) {
+            if (fromReal.length != fromImaginary.length) {
+                throw new IllegalArgumentException("Need the same amount of real and imaginary parts");
+            }
+            realParts = fromReal;
+            imaginaryParts = fromImaginary;
+            size = fromReal.length;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex get(int index) {
+            rangeCheck(index);
+            return Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getReal(int index) {
+            rangeCheck(index);
+            return realParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public double getImaginary(int index) {
+            rangeCheck(index);
+            return imaginaryParts[index];
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public Complex set(int index, Complex number) {
+            rangeCheck(index);
+            final Complex oldValue = Complex.ofCartesian(realParts[index], imaginaryParts[index]);
+            realParts[index] = number.getReal();
+            imaginaryParts[index] = number.getImaginary();
+            return oldValue;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setReal(int index, double real) {
+            rangeCheck(index);
+            realParts[index] = real;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void setImaginary(int index, double imaginary) {
+            rangeCheck(index);
+            imaginaryParts[index] = imaginary;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        double[] toArrayReal() {
+            final int length = size;
+            final double[] real = new double[length];
+            System.arraycopy(realParts, 0, real, 0, length);
+            return real;
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        double[] toArrayImaginary() {
+            final int length = size;
+            final double[] imaginary = new double[length];
+            System.arraycopy(imaginaryParts, 0, imaginary, 0, length);
+            return imaginary;
+        }
+
+        /**
+         * Increases the capacity of this ComplexNonInterleavedList instance, if necessary, to ensure that it can hold at
+         * least the amount of complex numbers specified by the minimum capacity argument.
+         *
+         * @param minCapacity Desired minimum capacity.
+         * @throws OutOfMemoryError if the {@code minCapacity} is greater than {@code MAX_ARRAY_SIZE}.
+         */
+        private void ensureCapacityInternal(int minCapacity) {
+            modCount++;
+            final long minArrayCapacity = Integer.toUnsignedLong(minCapacity);
+            if (minArrayCapacity > MAX_ARRAY_SIZE) {
+                throw new OutOfMemoryError(String.format(OOM_ERROR_STRING, minArrayCapacity));
+            }
+            final long oldArrayCapacity = realParts.length;
+            if (minArrayCapacity > oldArrayCapacity) {
+                long newArrayCapacity = oldArrayCapacity + (oldArrayCapacity >> 1);
+                // Round-odd up to even

Review Comment:
   Rounding to even is not required here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org