From 0eb6c30e048885090220aeb18e47c215c13260a3 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Thu, 12 Sep 2024 18:13:33 +0200 Subject: [PATCH] OAK-11110: Remove usage of Guava Iterables.any() (#1709) * OAK-11110: Remove usage of Guava Iterables.any() * OAK-11110: Remove usage of Guava Iterables.any() - non statics --- .../oak/plugins/index/property/PropertyIndexPlan.java | 3 +-- .../jackrabbit/oak/plugins/nodetype/TypeEditor.java | 7 ++++--- .../jackrabbit/oak/plugins/nodetype/TypePredicate.java | 8 ++++---- .../oak/plugins/index/lucene/LucenePropertyIndex.java | 5 +++-- .../jackrabbit/oak/composite/CompositeNodeStore.java | 8 ++++---- .../jackrabbit/oak/plugins/document/SplitOperations.java | 6 +++--- .../oak/plugins/document/DocumentSplitTest.java | 2 +- .../oak/plugins/document/VersionGCQueryTest.java | 2 +- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java index 76fbc914dac..6767777478c 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.index.property; -import static org.apache.jackrabbit.guava.common.collect.Iterables.any; import static java.util.Collections.emptySet; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME; @@ -109,7 +108,7 @@ public class PropertyIndexPlan { this.matchesAllTypes = !definition.hasProperty(DECLARING_NODE_TYPES); this.deprecated = definition.getBoolean(IndexConstants.INDEX_DEPRECATED); this.matchesNodeTypes = - matchesAllTypes || any(types, x -> filter.getSupertypes().contains(x)); + matchesAllTypes || CollectionUtils.toStream(types).anyMatch(filter.getSupertypes()::contains); ValuePattern valuePattern = new ValuePattern(definition); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java index 3dc672ef441..30a18ad79c6 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java @@ -17,7 +17,7 @@ package org.apache.jackrabbit.oak.plugins.nodetype; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.any; + import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN; import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES; import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; @@ -49,6 +49,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory; import org.apache.jackrabbit.oak.spi.commit.DefaultEditor; @@ -175,7 +176,7 @@ public static TypeEditor create(@NotNull ConstraintViolationCallback callback, S this.checkThisNode = typesToCheck == null || typesToCheck.contains(primary) - || any(mixins, x -> typesToCheck.contains(x)); + || CollectionUtils.toStream(mixins).anyMatch(typesToCheck::contains); this.parent = null; this.nodeName = null; this.types = requireNonNull(types); @@ -195,7 +196,7 @@ private TypeEditor( this.checkThisNode = typesToCheck == null || typesToCheck.contains(primary) - || any(mixins, x -> typesToCheck.contains(x)); + || CollectionUtils.toStream(mixins).anyMatch(typesToCheck::contains); this.parent = requireNonNull(parent); this.nodeName = requireNonNull(name); this.types = parent.types; diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java index a6070256704..68f5e994b62 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypePredicate.java @@ -33,7 +33,7 @@ import static java.util.Collections.singleton; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.any; + import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES; import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN; import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES; @@ -161,7 +161,7 @@ public boolean test(String primary, Set mixins) { if (primaryTypes != null && primaryTypes.contains(primary)) { return true; } - if (mixinTypes != null && any(mixins, x -> mixinTypes.contains(x))) { + if (mixinTypes != null && CollectionUtils.toStream(mixins).anyMatch(mixinTypes::contains)) { return true; } return false; @@ -175,7 +175,7 @@ public boolean test(@Nullable Tree input) { return true; } if (mixinTypes != null - && any(TreeUtil.getNames(input, JCR_MIXINTYPES), x -> mixinTypes.contains(x))) { + && CollectionUtils.toStream(TreeUtil.getNames(input, JCR_MIXINTYPES)).anyMatch(mixinTypes::contains)) { return true; } } @@ -193,7 +193,7 @@ public boolean test(@Nullable NodeState input) { return true; } if (mixinTypes != null - && any(input.getNames(JCR_MIXINTYPES), x -> mixinTypes.contains(x))) { + && CollectionUtils.toStream(input.getNames(JCR_MIXINTYPES)).anyMatch(mixinTypes::contains)) { return true; } } diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java index 74b9f2d7ee3..9a1ffaad678 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java @@ -47,6 +47,7 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.PerfLogger; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier; import org.apache.jackrabbit.oak.plugins.index.lucene.util.fv.SimSearchUtils; import org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter; @@ -1089,7 +1090,7 @@ private static void addNonFullTextConstraints(List qs, // deduced if (planResult.isPathTransformed()) { String parentPathSegment = planResult.getParentPathSegment(); - if (!Iterables.any(PathUtils.elements(parentPathSegment), "*"::equals)) { + if (!CollectionUtils.toStream(PathUtils.elements(parentPathSegment)).anyMatch("*"::equals)) { qs.add(new TermQuery(newPathTerm(path + parentPathSegment))); } } else { @@ -1107,7 +1108,7 @@ private static void addNonFullTextConstraints(List qs, // deduced if (planResult.isPathTransformed()) { String parentPathSegment = planResult.getParentPathSegment(); - if (!Iterables.any(PathUtils.elements(parentPathSegment), "*"::equals)) { + if (!CollectionUtils.toStream(PathUtils.elements(parentPathSegment)).anyMatch("*"::equals)) { qs.add(new TermQuery(newPathTerm(getParentPath(path) + parentPathSegment))); } } else { diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java index 5665b5bff5c..60949fe351a 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java @@ -17,12 +17,12 @@ package org.apache.jackrabbit.oak.composite; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.composite.checks.NodeStoreChecks; import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher; import org.apache.jackrabbit.oak.spi.commit.CommitHook; @@ -57,7 +57,7 @@ import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.collect.ImmutableMap.copyOf; -import static org.apache.jackrabbit.guava.common.collect.Iterables.any; + import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; @@ -270,7 +270,7 @@ public NodeState retrieve(String checkpoint) { } nodeStates.put(nodeStore, nodeState); } - if (any(nodeStates.values(), x -> x == null)) { + if (nodeStates.values().contains(null)) { LOG.warn("Checkpoint {} doesn't exist. Debug info:\n{}", checkpoint, checkpointDebugInfo(), new Exception()); return null; } @@ -320,7 +320,7 @@ private String getPartialCheckpointName(MountedNodeStore nodeStore, String globa } private static boolean checkpointExists(NodeStore nodeStore, String checkpoint) { - return Iterables.any(nodeStore.checkpoints(), x -> Objects.equals(x, checkpoint)); + return CollectionUtils.toStream(nodeStore.checkpoints()).anyMatch(x -> Objects.equals(x, checkpoint)); } private String checkpointDebugInfo() { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/SplitOperations.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/SplitOperations.java index e3090715862..50348c22541 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/SplitOperations.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/SplitOperations.java @@ -31,6 +31,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; @@ -43,8 +44,7 @@ import org.apache.jackrabbit.guava.common.collect.Maps; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.any; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.guava.common.collect.Sets.filter; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.COMMIT_ROOT; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.DOC_SIZE_THRESHOLD; @@ -228,7 +228,7 @@ private void populateSplitRevs() { } private boolean hasBinaryPropertyForSplit(Iterable values) { - return doc.hasBinary() && any(transform(values, binarySize::apply), BINARY_FOR_SPLIT_THRESHOLD::test); + return doc.hasBinary() && CollectionUtils.toStream(values).map(binarySize).anyMatch(BINARY_FOR_SPLIT_THRESHOLD); } /** diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentSplitTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentSplitTest.java index ee56c370038..9b47f0e5c2c 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentSplitTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentSplitTest.java @@ -455,7 +455,7 @@ private void cascadingSplit(String path) { List prevDocs = ImmutableList.copyOf(doc.getAllPreviousDocs()); //1 intermediate and 11 previous doc assertEquals(1 + 11, prevDocs.size()); - assertTrue(Iterables.any(prevDocs, input -> input.getSplitDocType() == SplitDocType.INTERMEDIATE)); + assertTrue(prevDocs.stream().anyMatch(input -> input.getSplitDocType() == SplitDocType.INTERMEDIATE)); for (String s : revs) { Revision r = Revision.fromString(s); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCQueryTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCQueryTest.java index 76b8817272b..928b70a6db8 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCQueryTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCQueryTest.java @@ -123,7 +123,7 @@ public void queryDeepPreviousDocs() throws Exception { builder.child("test"); merge(builder); String id = Utils.getIdFromPath("/test"); - while (!Iterables.any(store.find(Collection.NODES, id).getPreviousRanges().values(), INTERMEDIATE::test)) { + while (!store.find(Collection.NODES, id).getPreviousRanges().values().stream().anyMatch(INTERMEDIATE::test)) { InputStream s = new RandomStream(10 * 1024, 42); PropertyState p = new BinaryPropertyState("p", ns.createBlob(s)); builder = ns.getRoot().builder();