arne-bdt commented on code in PR #1918:
URL: https://github.com/apache/jena/pull/1918#discussion_r1241269304


##########
jena-core/src/main/java/org/apache/jena/mem2/spliterator/ArraySpliterator.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.mem2.spliterator;
+
+import java.util.Spliterator;
+import java.util.function.Consumer;
+
+/**
+ * A spliterator for arrays. This spliterator will iterate over the array
+ * entries within the given boundaries.
+ * <p>
+ * This spliterator supports splitting into sub-spliterators.
+ * <p>
+ * The spliterator will check for concurrent modifications by invoking a 
{@link Runnable}
+ * before each action.
+ *
+ * @param <E>
+ */
+public class ArraySpliterator<E> implements Spliterator<E> {
+
+    private final E[] entries;
+    private final int fromIndex;
+    private final Runnable checkForConcurrentModification;
+    private int pos;
+
+    /**
+     * Create a spliterator for the given array, with the given size.
+     *
+     * @param entries                        the array
+     * @param fromIndex                      the index of the first element, 
inclusive
+     * @param toIndex                        the index of the last element, 
exclusive
+     * @param checkForConcurrentModification runnable to check for concurrent 
modifications
+     */
+    public ArraySpliterator(final E[] entries, final int fromIndex, final int 
toIndex, final Runnable checkForConcurrentModification) {
+        this.entries = entries;
+        this.fromIndex = fromIndex;
+        this.pos = toIndex;
+        this.checkForConcurrentModification = checkForConcurrentModification;
+    }
+
+    /**
+     * Create a spliterator for the given array, with the given size.
+     *
+     * @param entries                        the array
+     * @param checkForConcurrentModification runnable to check for concurrent 
modifications
+     */
+    public ArraySpliterator(final E[] entries, final Runnable 
checkForConcurrentModification) {
+        this(entries, 0, entries.length, checkForConcurrentModification);
+    }
+
+    @Override
+    public boolean tryAdvance(Consumer<? super E> action) {
+        this.checkForConcurrentModification.run();
+        if (fromIndex <= --pos) {
+            action.accept(entries[pos]);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void forEachRemaining(Consumer<? super E> action) {
+        while (fromIndex <= --pos) {
+            action.accept(entries[pos]);
+        }
+        this.checkForConcurrentModification.run();
+    }
+
+    @Override
+    public Spliterator<E> trySplit() {
+        final int entriesCount = pos - fromIndex;
+        if (entriesCount < 2) {
+            return null;
+        }
+        final int toIndexOfSubIterator = this.pos;
+        this.pos = fromIndex + (entriesCount >>> 1);
+        return new ArraySpliterator<>(entries, this.pos, toIndexOfSubIterator, 
checkForConcurrentModification);
+    }
+
+    @Override
+    @SuppressWarnings("squid:S2184")
+    public long estimateSize() {
+        return pos - fromIndex;

Review Comment:
   I just removed the SuppressWarnings. Either way sonar lint does not like it.
   With the (long) cast it says:
   - Remove this unnecessary cast to "long".
   - Casting '(pos - fromIndex)' to 'long' is redundant 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to