Skip to content

Commit

Permalink
OAK-11229: remove usage of newArrayList(Iterable/Iterator) (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
reschke authored Oct 30, 2024
1 parent a7057be commit f717b97
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ protected long sweep(GarbageCollectorFileState fs, long markStart, boolean force
count += ids.size();
deleted += BlobCollectionType.get(blobStore)
.sweepInternal(blobStore, ids, removesQueue, maxModifiedTime);
saveBatchToFile(newArrayList(removesQueue), removesWriter);
saveBatchToFile(new ArrayList<>(removesQueue), removesWriter);

for(String deletedId : removesQueue) {
// Estimate the size of the blob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.jackrabbit.oak.plugins.index.aggregate;

import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.api.Type.STRING;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
Expand All @@ -34,6 +33,7 @@
import java.util.Set;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.spi.query.QueryIndex;
import org.apache.jackrabbit.oak.spi.state.NodeState;

Expand Down Expand Up @@ -86,7 +86,7 @@ private Iterator<String> getParents(NodeState root, String path,
parentPath = getParentPath(parentPath);
if (isNodeType(root, parentPath, primaryType)) {
parents.add(parentPath);
parents.addAll(newArrayList(getParents(root, parentPath,
parents.addAll(CollectionUtils.toList(getParents(root, parentPath,
false)));
return parents.iterator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,10 @@ public void sortQueriesWithStringIgnoredMulti_OrderedProps() throws Exception {
child.setProperty("bar", "baz");
root.commit();

assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]", Lists
.newArrayList(Iterables.concat(Lists.newArrayList("/test/a"), getSortedPaths(tuples, OrderDirection.ASC))));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", Lists
.newArrayList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC), Lists.newArrayList("/test/a")
)));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]", CollectionUtils
.toList(Iterables.concat(Lists.newArrayList("/test/a"), getSortedPaths(tuples, OrderDirection.ASC))));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", CollectionUtils
.toList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC), Lists.newArrayList("/test/a"))));
}

void assertSortedString() throws CommitFailedException {
Expand Down Expand Up @@ -1274,14 +1273,11 @@ public void sortQueriesWithDateStringMixed_OrderedProps() throws Exception {
root.commit();

// Add the path of property added as timestamp string in the sorted list
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]",
CollectionUtils.toList(Iterables.concat(Lists.newArrayList("/test/n0"),
getSortedPaths(tuples, OrderDirection.ASC))));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]", CollectionUtils
.toList(Iterables.concat(Lists.newArrayList("/test/n0"), getSortedPaths(tuples, OrderDirection.ASC))));
// Append the path of property added as timestamp string to the sorted list
assertOrderedQuery(
"select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", Lists
.newArrayList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC),
Lists.newArrayList("/test/n0"))));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", CollectionUtils
.toList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC), Lists.newArrayList("/test/n0"))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.FileIOUtils;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever;
import org.apache.jackrabbit.oak.plugins.blob.GarbageCollectorFileState;
Expand Down Expand Up @@ -247,7 +248,7 @@ private HashSet<String> addNodeSpecialChars() throws Exception {
NodeBuilder n = a.child("cspecial");
n.child(specialCharSets.get(i)).setProperty("x", b);
Iterator<String> idIter = blobStore.resolveChunks(b.getBlobId());
set.addAll(Lists.newArrayList(idIter));
set.addAll(CollectionUtils.toList(idIter));
}
nodeStore.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
return set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ public <T extends Document> List<T> createOrUpdate(Collection<T> collection,
// in bulk mode wouldn't result in any performance gain
break;
}
for (List<UpdateOp> partition : CollectionUtils.partitionList(Lists.newArrayList(operationsToCover.values()), bulkSize)) {
for (List<UpdateOp> partition : CollectionUtils.partitionList(new ArrayList<>(operationsToCover.values()), bulkSize)) {
Map<UpdateOp, T> successfulUpdates = bulkUpdate(collection, partition, oldDocs);
results.putAll(successfulUpdates);
operationsToCover.values().removeAll(successfulUpdates.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.jackrabbit.oak.plugins.document.rdb;

import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.oak.plugins.document.UpdateUtils.checkConditions;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.asDocumentStoreException;
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.closeResultSet;
Expand Down Expand Up @@ -422,7 +421,7 @@ private <T extends Document> List<T> internalCreateOrUpdate(Collection<T> collec
break;
}

for (List<UpdateOp> partition : CollectionUtils.partitionList(newArrayList(operationsToCover.values()), CHUNKSIZE)) {
for (List<UpdateOp> partition : CollectionUtils.partitionList(new ArrayList<>(operationsToCover.values()), CHUNKSIZE)) {
Map<UpdateOp, T> successfulUpdates = bulkUpdate(collection, partition, oldDocs, upsert);
results.putAll(successfulUpdates);
operationsToCover.values().removeAll(successfulUpdates.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.commons.FileIOUtils;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever;
import org.apache.jackrabbit.oak.plugins.blob.GarbageCollectorFileState;
Expand Down Expand Up @@ -189,7 +190,7 @@ private HashSet<String> addNodeSpecialChars() throws Exception {
Iterator<String> idIter =
((GarbageCollectableBlobStore) ds.getBlobStore())
.resolveChunks(b.toString());
set.addAll(Lists.newArrayList(idIter));
set.addAll(CollectionUtils.toList(idIter));
}
ds.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
return set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.guava.common.cache.RemovalCause;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
Expand All @@ -40,7 +41,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -155,7 +155,7 @@ public boolean addPut(PathRev key, StringValue value) {
}

public boolean addInvalidate(Iterable<PathRev> keys) {
invalidateActions.addAll(newArrayList(keys));
invalidateActions.addAll(CollectionUtils.toList(keys));
return wrapped.addInvalidate(keys);
}
}
Expand Down

0 comments on commit f717b97

Please sign in to comment.