Skip to content

Commit

Permalink
OAK-11110: Remove usage of Guava Iterables.any() (apache#1709)
Browse files Browse the repository at this point in the history
* OAK-11110: Remove usage of Guava Iterables.any()

* OAK-11110: Remove usage of Guava Iterables.any() - non statics
  • Loading branch information
reschke authored Sep 12, 2024
1 parent a7702b8 commit 0eb6c30
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,7 +161,7 @@ public boolean test(String primary, Set<String> 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;
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1089,7 +1090,7 @@ private static void addNonFullTextConstraints(List<Query> 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 {
Expand All @@ -1107,7 +1108,7 @@ private static void addNonFullTextConstraints(List<Query> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -228,7 +228,7 @@ private void populateSplitRevs() {
}

private boolean hasBinaryPropertyForSplit(Iterable<String> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private void cascadingSplit(String path) {
List<NodeDocument> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0eb6c30

Please sign in to comment.