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

reschke pushed a commit to branch OAK-11023
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/OAK-11023 by this push:
     new 41eceb9b6b OAK-11023: Remove usage of Guava newArrayList (w.i.p.)
41eceb9b6b is described below

commit 41eceb9b6b56e6f6fd16a7edd32d8fcfb6c5871d
Author: Julian Reschke <[email protected]>
AuthorDate: Sun Sep 1 13:34:20 2024 +0100

    OAK-11023: Remove usage of Guava newArrayList (w.i.p.)
---
 .../oak/plugins/blob/datastore/BlobIdTracker.java  | 35 +++++++++++-----------
 .../blob/datastore/SharedDataStoreTest.java        |  9 +++---
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git 
a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java
 
b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java
index 1e55e1ba7f..7b9dd3b232 100644
--- 
a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java
+++ 
b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java
@@ -24,12 +24,15 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
 
 import org.apache.jackrabbit.guava.common.base.Stopwatch;
 import org.apache.jackrabbit.guava.common.io.Files;
@@ -44,8 +47,6 @@ import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.guava.common.collect.Iterables.transform;
-import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
 import static org.apache.jackrabbit.guava.common.io.Files.move;
 import static org.apache.jackrabbit.guava.common.io.Files.newWriter;
 import static java.io.File.createTempFile;
@@ -266,18 +267,18 @@ public class BlobIdTracker implements Closeable, 
BlobTracker {
             Iterable<DataRecord> refRecords = 
datastore.getAllMetadataRecords(fileNamePrefix);
 
             // Download all the corresponding files for the records
-            List<File> refFiles = newArrayList(transform(refRecords, input -> {
-                    InputStream inputStream = null;
-                    try {
-                        inputStream = input.getStream();
-                        return copy(inputStream);
-                    } catch (Exception e) {
-                        LOG.warn("Error copying data store file locally {}", 
input.getIdentifier(), e);
-                    } finally {
-                        closeQuietly(inputStream);
-                    }
-                    return null;
-                }));
+            List<File> refFiles = 
StreamSupport.stream(refRecords.spliterator(), false).map(input -> {
+                InputStream inputStream = null;
+                try {
+                    inputStream = input.getStream();
+                    return copy(inputStream);
+                } catch (Exception e) {
+                    LOG.warn("Error copying data store file locally {}", 
input.getIdentifier(), e);
+                } finally {
+                    closeQuietly(inputStream);
+                }
+                return null;
+            }).collect(Collectors.toList());
             LOG.info("Retrieved all blob id files in [{}]", 
watch.elapsed(TimeUnit.MILLISECONDS));
 
             // Merge all the downloaded files in to the local store
@@ -393,7 +394,7 @@ public class BlobIdTracker implements Closeable, 
BlobTracker {
         public void track(File recs) throws IOException {
             lock.lock();
             try {
-                append(List.of(recs), delFile, false);
+                append(new ArrayList<>(List.of(recs)), delFile, false);
                 sort(delFile);
             } finally {
                 lock.unlock();
@@ -687,7 +688,7 @@ public class BlobIdTracker implements Closeable, 
BlobTracker {
             File added = createTempFile("added", null);
             writeStrings(recs, added, false);
             // Merge the file with the references
-            merge(List.of(added), false);
+            merge(new ArrayList<>(List.of(added)), false);
         }
 
         /**
@@ -698,7 +699,7 @@ public class BlobIdTracker implements Closeable, 
BlobTracker {
          */
         protected void addRecords(File recs) throws IOException {
             // Merge the file with the references
-            merge(List.of(recs), false);
+            merge(new ArrayList<>(List.of(recs)), false);
         }
 
         /**
diff --git 
a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/SharedDataStoreTest.java
 
b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/SharedDataStoreTest.java
index f71465461e..f38c2e6182 100644
--- 
a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/SharedDataStoreTest.java
+++ 
b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/SharedDataStoreTest.java
@@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -228,7 +229,7 @@ public class SharedDataStoreTest {
 
         final String data = "testData";
         for (boolean fromInputStream : List.of(false, true)) {
-            for (String name : List.of(null, "")) {
+            for (String name : Arrays.asList(null, "")) {
                 try {
                     if (fromInputStream) {
                         fds.addMetadataRecord(new 
ByteArrayInputStream(data.getBytes()), name);
@@ -253,7 +254,7 @@ public class SharedDataStoreTest {
 
         fds.addMetadataRecord(randomStream(0, 10), "testRecord");
         assertNull(fds.getMetadataRecord("invalid"));
-        for (String name : List.of("", null)) {
+        for (String name : Arrays.asList("", null)) {
             try {
                 fds.getMetadataRecord(name);
                 fail("Expect to throw");
@@ -308,7 +309,7 @@ public class SharedDataStoreTest {
         SharedDataStore fds = dataStore;
 
         fds.addMetadataRecord(randomStream(0, 10), "name");
-        for (String name : List.of("", null)) {
+        for (String name : Arrays.asList("", null)) {
             if (Strings.isNullOrEmpty(name)) {
                 try {
                     fds.deleteMetadataRecord(name);
@@ -382,7 +383,7 @@ public class SharedDataStoreTest {
         SharedDataStore fds = dataStore;
 
         fds.addMetadataRecord(randomStream(0, 10), "name");
-        for (String name : List.of("invalid", "", null)) {
+        for (String name : Arrays.asList("invalid", "", null)) {
             if (Strings.isNullOrEmpty(name)) {
                 try {
                     fds.metadataRecordExists(name);

Reply via email to