From e4db4c691036f22724f9e0939199c8b38e8fe375 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 10 Aug 2024 16:42:56 +0200 Subject: [PATCH] OAK-11012: Remove usage of Guava Objects.equal() (#1634) --- .../jackrabbit/oak/commons/CIHelper.java | 10 ++++----- .../oak/jcr/observation/ObservationTest.java | 21 ++++++++++--------- .../oak/plugins/document/Commit.java | 4 ++-- .../oak/plugins/document/NodeDocument.java | 5 +++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/CIHelper.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/CIHelper.java index bcf707b71b0..d70fe035fce 100644 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/CIHelper.java +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/CIHelper.java @@ -16,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.commons; -import static org.apache.jackrabbit.guava.common.base.Objects.equal; import static java.lang.Boolean.parseBoolean; import static java.lang.System.getenv; +import java.util.Objects; + import org.apache.jackrabbit.guava.common.base.StandardSystemProperty; /** @@ -57,7 +57,7 @@ public static boolean travis() { * @deprecated Travis builds do not use PROFILE anymore. Use {@link #travis()} instead. */ public static boolean travisPedantic() { - return equal(getenv("PROFILE"), "pedantic"); + return Objects.equals(getenv("PROFILE"), "pedantic"); } /** @@ -65,7 +65,7 @@ public static boolean travisPedantic() { * @deprecated Travis builds do not use PROFILE anymore. Use {@link #travis()} instead. */ public static boolean travisUnitTesting() { - return equal(getenv("PROFILE"), "unittesting"); + return Objects.equals(getenv("PROFILE"), "unittesting"); } /** @@ -73,7 +73,7 @@ public static boolean travisUnitTesting() { * @deprecated Travis builds do not use PROFILE anymore. Use {@link #travis()} instead. */ public static boolean travisIntegrationTesting() { - return equal(getenv("PROFILE"), "integrationTesting"); + return Objects.equals(getenv("PROFILE"), "integrationTesting"); } public static boolean jenkinsNodeLabel(String label) { diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java index cdbe9346e24..dd784bac75e 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/ObservationTest.java @@ -19,7 +19,7 @@ package org.apache.jackrabbit.oak.jcr.observation; import static org.apache.jackrabbit.guava.common.collect.Sets.newHashSet; -import static org.apache.jackrabbit.guava.common.base.Objects.equal; + import static java.util.Collections.synchronizedList; import static java.util.Collections.synchronizedSet; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; @@ -48,6 +48,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -1257,7 +1258,7 @@ public Expectation expect(Expectation expectation) { expected.add(expectation); return expectation; } - + public Expectation optional(Expectation expectation) { if (failed != null) { expectation.fail(failed); @@ -1270,7 +1271,7 @@ public Future expect(final String path, final int type) { return expect(new Expectation("path = " + path + ", type = " + type) { @Override public boolean onEvent(Event event) throws RepositoryException { - return type == event.getType() && equal(path, event.getPath()); + return type == event.getType() && Objects.equals(path, event.getPath()); } }); } @@ -1279,7 +1280,7 @@ public Future expect(final String path, final String identifier, final in return expect(new Expectation("path = " + path + ", identifier = " + identifier + ", type = " + type) { @Override public boolean onEvent(Event event) throws RepositoryException { - return type == event.getType() && equal(path, event.getPath()) && equal(identifier, event.getIdentifier()); + return type == event.getType() && Objects.equals(path, event.getPath()) && Objects.equals(identifier, event.getIdentifier()); } }); } @@ -1316,9 +1317,9 @@ public void expectMove(final String src, final String dst) { @Override public boolean onEvent(Event event) throws Exception { return event.getType() == NODE_MOVED && - equal(dst, event.getPath()) && - equal(src, event.getInfo().get("srcAbsPath")) && - equal(dst, event.getInfo().get("destAbsPath")); + Objects.equals(dst, event.getPath()) && + Objects.equals(src, event.getInfo().get("srcAbsPath")) && + Objects.equals(dst, event.getInfo().get("destAbsPath")); } }); } @@ -1327,8 +1328,8 @@ public void expectValue(final Value before, final Value after) { expect(new Expectation("Before value " + before + " after value " + after) { @Override public boolean onEvent(Event event) throws Exception { - return equal(before, event.getInfo().get("beforeValue")) && - equal(after, event.getInfo().get("afterValue")); + return Objects.equals(before, event.getInfo().get("beforeValue")) && + Objects.equals(after, event.getInfo().get("afterValue")); } }); } @@ -1347,7 +1348,7 @@ public Future expectBeforeValue(final String path, final int type, final return expect(new Expectation("path = " + path + ", type = " + type + ", beforeValue = " + beforeValue) { @Override public boolean onEvent(Event event) throws RepositoryException { - return type == event.getType() && equal(path, event.getPath()) && event.getInfo().containsKey("beforeValue") && beforeValue.equals(((Value)event.getInfo().get("beforeValue")).getString()); + return type == event.getType() && Objects.equals(path, event.getPath()) && event.getInfo().containsKey("beforeValue") && beforeValue.equals(((Value)event.getInfo().get("beforeValue")).getString()); } }); } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java index 774185ef51b..b56c8af6e05 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.NavigableSet; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.TimeUnit; @@ -41,7 +42,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.jackrabbit.guava.common.base.Objects.equal; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull; import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; @@ -697,7 +697,7 @@ private String formatConflictRevision(Revision r) { return r + " (not yet visible)"; } else if (baseRevision != null && !baseRevision.isRevisionNewer(r) - && !equal(baseRevision.getRevision(r.getClusterId()), r)) { + && !Objects.equals(baseRevision.getRevision(r.getClusterId()), r)) { return r + " (older than base " + baseRevision + ")"; } else { return r.toString(); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java index a22486ce2e5..2c76fa126e4 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.NavigableMap; +import java.util.Objects; import java.util.Queue; import java.util.Set; import java.util.SortedMap; @@ -60,7 +61,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets; import static java.util.stream.Collectors.toSet; -import static org.apache.jackrabbit.guava.common.base.Objects.equal; + import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull; import static org.apache.jackrabbit.guava.common.collect.ImmutableList.copyOf; @@ -744,7 +745,7 @@ Revision getNewestRevision(final RevisionContext context, clusterIds = Sets.newHashSet(); for (Revision prevRev : getPreviousRanges().keySet()) { if (lower.isRevisionNewer(prevRev) || - equal(prevRev, lower.getRevision(prevRev.getClusterId()))) { + Objects.equals(prevRev, lower.getRevision(prevRev.getClusterId()))) { clusterIds.add(prevRev.getClusterId()); } }