From b55e398bb98ff06109f1c9922f058e71112ac7f7 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Thu, 23 Jan 2025 20:11:30 +0530 Subject: [PATCH 1/3] OAK-11427 : removed usage of Guava Iterables.isEmpty --- .../SyncHandlerMappingTrackerTest.java | 17 ++--- .../ldap/impl/LdapIdentityProviderTest.java | 3 +- .../authorization/cug/impl/NestedCugHook.java | 3 +- .../PrincipalPolicyValidatorProvider.java | 3 +- .../impl/PrincipalPolicyImporterTest.java | 3 +- .../commons/collections/IterableUtils.java | 48 ++++++++++++++ .../collections/IterableUtilsTest.java | 65 +++++++++++++++++++ .../plugins/nodetype/TypeRegistration.java | 4 +- .../accesscontrol/AccessControlValidator.java | 3 +- .../property/AsyncPropertyIndexTest.java | 9 +-- .../oak/plugins/tree/impl/TreeUtilTest.java | 17 ++--- .../oak/jcr/observation/EventFactory.java | 4 +- .../LuceneJournalPropertyBuilderTest.java | 5 +- .../plugins/index/search/IndexDefinition.java | 3 +- .../privilege/PrivilegeBitsProvider.java | 5 +- .../oak/plugins/tree/TreeUtilTest.java | 3 +- .../security/CompositeConfigurationTest.java | 5 +- .../privilege/PrivilegeBitsProviderTest.java | 7 +- 18 files changed, 167 insertions(+), 40 deletions(-) create mode 100644 oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java create mode 100644 oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java index 48fd1670018..d5eac6dd834 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping; import org.junit.Before; @@ -49,21 +50,21 @@ public void before() { @Test public void testAddingServiceWithoutProperties() { tracker.addingService(ref); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test public void testAddingServiceWithIdpProp() { when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP"); tracker.addingService(ref); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test public void testAddingServiceWithSyncHandlerProp() { when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); tracker.addingService(ref); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test @@ -94,21 +95,21 @@ public void testAddingServiceWithProperties() { @Test public void testModifiedServiceWithoutProperties() { tracker.modifiedService(ref, service); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test public void testModifiedServiceWithIdpProp() { when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP"); tracker.modifiedService(ref, service); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test public void testModifiedServiceWithSyncHandlerProp() { when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); tracker.modifiedService(ref, service); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } @Test @@ -126,7 +127,7 @@ public void testModifiedServiceWithProperties() { when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH-3"); when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-3"); tracker.modifiedService(ref, service); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); assertEquals(Set.of("testIDP-3"), SetUtils.toSet(tracker.getIdpNames("testSH-3"))); } @@ -138,6 +139,6 @@ public void testRemovedService() { tracker.addingService(ref); tracker.removedService(ref, service); - assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); + assertTrue(IterableUtils.isEmpty(tracker.getIdpNames("testSH"))); } } \ No newline at end of file diff --git a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java index 6b562f0a7d9..9887a750445 100644 --- a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java +++ b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java @@ -19,6 +19,7 @@ import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; @@ -211,7 +212,7 @@ public void testGetDeclaredMembersInvalidMemberAttribute() throws Exception { ExternalGroup gr = idp.getGroup(TEST_GROUP1_NAME); Iterable memberrefs = gr.getDeclaredMembers(); - assertTrue(Iterables.isEmpty(memberrefs)); + assertTrue(IterableUtils.isEmpty(memberrefs)); } @Test diff --git a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java index 87464a8b6a1..d3901181102 100644 --- a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java +++ b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java @@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.PostValidationHook; @@ -294,7 +295,7 @@ public boolean childNodeDeleted(String name, NodeState before) { // are still present. Set reconnect = getCugPathsToReconnect(before); if (isRoot) { - if (!Iterables.isEmpty(reconnect)) { + if (!IterableUtils.isEmpty(reconnect)) { afterBuilder.setProperty(HIDDEN_NESTED_CUGS, reconnect, Type.STRINGS); afterBuilder.setProperty(HIDDEN_TOP_CUG_CNT, reconnect.size()); } diff --git a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java index 8ab663830b8..8dfa07f90a9 100644 --- a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java +++ b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java @@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.StringUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.conditions.Validate; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate; @@ -221,7 +222,7 @@ private void validateEntry(@NotNull String name, @NotNull NodeState nodeState) t throw accessControlViolation(36, "Isolated entry of principal policy at " + entryPath); } Iterable privilegeNames = nodeState.getNames(REP_PRIVILEGES); - if (Iterables.isEmpty(privilegeNames)) { + if (IterableUtils.isEmpty(privilegeNames)) { throw accessControlViolation(37, "Empty rep:privileges property at " + entryPath); } PrivilegeManager privilegeManager = mgrProvider.getPrivilegeManager(); diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java index 99f9492c773..d63ec6f8077 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java @@ -20,6 +20,7 @@ import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration; @@ -474,7 +475,7 @@ public void testEndWithPolicyAndValidTree() throws Exception { policyTree = root.getTree(policyTree.getPath()); assertTrue(policyTree.exists()); assertTrue(policyTree.hasProperty(REP_PRINCIPAL_NAME)); - assertTrue(Iterables.isEmpty(policyTree.getChildren())); + assertTrue(IterableUtils.isEmpty(policyTree.getChildren())); } @Test(expected = IllegalStateException.class) diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java new file mode 100644 index 00000000000..ad88546c762 --- /dev/null +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.commons.collections; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * Utility methods for {@link Iterable} conversions. + */ +public class IterableUtils { + + private IterableUtils() { + // no instances for you + } + + /** + * Checks if an iterable is empty. + * + * @param iterable the iterable to check, must not be {@code null} + * @param the type of elements in the iterable + * @return {@code true} if the iterable is empty, {@code false} otherwise + * @throws NullPointerException if the iterable is {@code null} + */ + public static boolean isEmpty(@NotNull Iterable iterable) { + if (iterable instanceof Collection) { + return ((Collection) iterable).isEmpty(); + } + return StreamUtils.toStream(iterable).findAny().isEmpty(); + } +} diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java new file mode 100644 index 00000000000..630f90a3141 --- /dev/null +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.commons.collections; + + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; + +/** + * Unit tests for the {@link IterableUtils} class. + *

+ * This class contains test cases to verify the functionality of the methods + * in the {@link IterableUtils} class. + */ +public class IterableUtilsTest { + + @Test + public void testIsEmptyWithEmptyList() { + List emptyList = Collections.emptyList(); + Assert.assertTrue(IterableUtils.isEmpty(emptyList)); + } + + @Test + public void testIsEmptyWithNonEmptyList() { + List nonEmptyList = List.of("one", "two", "three"); + Assert.assertFalse(IterableUtils.isEmpty(nonEmptyList)); + } + + @Test + public void testIsEmptyWithEmptyIterable() { + Iterable emptyIterable = Collections::emptyIterator; + Assert.assertTrue(IterableUtils.isEmpty(emptyIterable)); + } + + @Test + public void testIsEmptyWithNonEmptyIterable() { + Iterable nonEmptyIterable = List.of("one", "two", "three"); + Assert.assertFalse(IterableUtils.isEmpty(nonEmptyIterable)); + } + + @Test + public void testIsEmptyWithNullIterable() { + Assert.assertThrows(NullPointerException.class, () -> IterableUtils.isEmpty(null)); + } + +} \ No newline at end of file diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java index 1ad0ff3cc92..133bc242994 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java @@ -18,7 +18,6 @@ import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll; import static org.apache.jackrabbit.guava.common.collect.Iterables.contains; -import static org.apache.jackrabbit.guava.common.collect.Iterables.isEmpty; import static java.util.Collections.emptyList; import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION; import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN; @@ -68,6 +67,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.ListUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; @@ -253,7 +253,7 @@ private void ensureNtBase(NodeBuilder types, NodeBuilder type) { // This is a primary node type. // Make sure jcr:supertypes contains nt:base when needed. Iterable supertypes = getNames(type, JCR_SUPERTYPES); - if (isEmpty(supertypes)) { + if (IterableUtils.isEmpty(supertypes)) { addNameToList(type, JCR_SUPERTYPES, NT_BASE); } else { // is any of the supertypes a primary node type? diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java index ff1ad6f7266..5aad767b524 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java @@ -32,6 +32,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate; import org.apache.jackrabbit.oak.plugins.tree.TreeConstants; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; @@ -270,7 +271,7 @@ private void checkValidPrivileges(@NotNull Tree aceNode) throws CommitFailedExce @NotNull private static Iterable getPrivilegeNames(@NotNull Tree aceNode) throws CommitFailedException { Iterable privilegeNames = TreeUtil.getNames(aceNode, REP_PRIVILEGES); - if (Iterables.isEmpty(privilegeNames)) { + if (IterableUtils.isEmpty(privilegeNames)) { throw accessViolation(9, "Missing privileges at " + aceNode.getPath()); } return privilegeNames; diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java index a300e8c1897..32c67cf583a 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.Set; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate; import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider; @@ -64,7 +65,7 @@ public class AsyncPropertyIndexTest { @Test public void testAsyncPropertyLookup() throws Exception { NodeStore store = new MemoryNodeStore(); - assertTrue(Iterables.isEmpty(store.checkpoints())); + assertTrue(IterableUtils.isEmpty(store.checkpoints())); NodeBuilder builder = store.getRoot().builder(); @@ -103,7 +104,7 @@ public void testAsyncPropertyLookup() throws Exception { async.close(); assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME) .getChildNode("foo").getString(ASYNC_PROPERTY_NAME)); - assertTrue(Iterables.isEmpty(store.checkpoints())); + assertTrue(IterableUtils.isEmpty(store.checkpoints())); // add content, it should be indexed synchronously builder = store.getRoot().builder(); @@ -131,12 +132,12 @@ private static Set find(PropertyIndexLookup lookup, String name, @Test public void testAsyncPropertyNoChanges() throws Exception { NodeStore store = new MemoryNodeStore(); - assertTrue(Iterables.isEmpty(store.checkpoints())); + assertTrue(IterableUtils.isEmpty(store.checkpoints())); AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true); async.run(); async.run(); async.close(); - assertTrue(Iterables.isEmpty(store.checkpoints())); + assertTrue(IterableUtils.isEmpty(store.checkpoints())); } } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java index ec8446fc8a3..cb600d98381 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java @@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.LazyValue; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.junit.Test; @@ -122,8 +123,8 @@ protected Tree createValue() { @Test public void testGetMixinTypeNamesMissingAccessible() { - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(root.getTree("/")))); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(root.getTree("/"), new LazyValue() { + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(root.getTree("/")))); + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(root.getTree("/"), new LazyValue() { @Override protected Tree createValue() { return root.getTree("/"); @@ -134,12 +135,12 @@ protected Tree createValue() { @Test public void testGetMixinTypeNamesMissingNotAccessible() throws Exception { Tree tree = root.getTree("/"); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(tree))); + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(tree))); try (ContentSession cs = login(new GuestCredentials())) { Root guestRoot = cs.getLatestRoot(); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree("/")))); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree("/"), new LazyValue() { + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree("/")))); + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree("/"), new LazyValue() { @Override protected Tree createValue() { return tree; @@ -177,8 +178,8 @@ public void testGetMixinTypeNamesPresentNotAccessible() throws Exception { try (ContentSession cs = login(new GuestCredentials())) { Root guestRoot = cs.getLatestRoot(); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree(path)))); - assertTrue(Iterables.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue() { + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree(path)))); + assertTrue(IterableUtils.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue() { @Override protected Tree createValue() { return testTree; @@ -197,7 +198,7 @@ public void testGetMixinTypeNamesPresentNotAccessibleNew() throws Exception { when(t.hasProperty(JcrConstants.JCR_MIXINTYPES)).thenReturn(false); when(t.getStatus()).thenReturn(Tree.Status.NEW); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(t, new LazyValue() { + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(t, new LazyValue() { @Override protected Tree createValue() { return testTree; diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java index d4b7e22ec83..f8409633f74 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java @@ -18,7 +18,6 @@ */ package org.apache.jackrabbit.oak.jcr.observation; -import static org.apache.jackrabbit.guava.common.collect.Iterables.isEmpty; import static org.apache.jackrabbit.guava.common.collect.Iterables.toArray; import static java.util.Collections.emptyMap; import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES; @@ -39,6 +38,7 @@ import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; @@ -221,7 +221,7 @@ public int getType() { } private Map createInfoMap(String primaryType, Iterable mixinTypes) { - if (isEmpty(mixinTypes)) { + if (IterableUtils.isEmpty(mixinTypes)) { return Map.of( JCR_PRIMARYTYPE, mapper.getJcrName(primaryType)); } else { diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java index 0e77906a373..c58ec52925d 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java @@ -22,6 +22,7 @@ import org.apache.jackrabbit.guava.common.collect.HashMultimap; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Multimap; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.junit.Test; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -40,7 +41,7 @@ public class LuceneJournalPropertyBuilderTest { public void nullProperty() throws Exception{ builder.addProperty(null); assertEquals("{}", builder.buildAsString()); - assertTrue(Iterables.isEmpty(((IndexedPaths)builder.build()))); + assertTrue(IterableUtils.isEmpty(((IndexedPaths)builder.build()))); } @Test @@ -51,7 +52,7 @@ public void nullOrEmptyJson() throws Exception{ builder2.addSerializedProperty(null); builder2.addSerializedProperty(builder.buildAsString()); - assertTrue(Iterables.isEmpty(((IndexedPaths)builder2.build()))); + assertTrue(IterableUtils.isEmpty(((IndexedPaths)builder2.build()))); } @Test public void addJsonLessThanMaxBuilderSize() throws Exception { diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java index c473fbf6300..f3797528ccd 100644 --- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java +++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java @@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; @@ -1617,7 +1618,7 @@ private static NodeBuilder createIndexRules(NodeState defn) { //Also include all immediate leaf propNode names for (ChildNodeEntry cne : propNodeState.getChildNodeEntries()) { if (!propNamesSet.contains(cne.getName()) - && Iterables.isEmpty(cne.getNodeState().getChildNodeNames())) { + && IterableUtils.isEmpty(cne.getNodeState().getChildNodeNames())) { propNamesSet.add(cne.getName()); } } diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java index 346b9d314cc..02c92e13f79 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java @@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.namepath.NameMapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -91,7 +92,7 @@ public PrivilegeBits getBits(@NotNull String... privilegeNames) { */ @NotNull public PrivilegeBits getBits(@NotNull Iterable privilegeNames) { - if (Iterables.isEmpty(privilegeNames)) { + if (IterableUtils.isEmpty(privilegeNames)) { return PrivilegeBits.EMPTY; } @@ -116,7 +117,7 @@ public PrivilegeBits getBits(@NotNull Iterable privilegeNames, boolean v if (!validateNames) { return getBits(privilegeNames); } - if (Iterables.isEmpty(privilegeNames)) { + if (IterableUtils.isEmpty(privilegeNames)) { return PrivilegeBits.EMPTY; } PrivilegeBits bits = PrivilegeBits.getInstance(); diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java index d84e973f252..ebea77b6777 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java @@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.commons.LazyValue; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.UUIDUtils; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.junit.Test; @@ -157,7 +158,7 @@ public void testGetMixinTypeNamesUnusedLazy() { @Test public void testGetMixinTypeNamesNewTreeLazy() { Tree newTree = when(rootTree.getChild("x").getStatus()).thenReturn(Tree.Status.NEW).getMock(); - assertTrue(Iterables.isEmpty(TreeUtil.getMixinTypeNames(newTree, new LazyValue() { + assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(newTree, new LazyValue() { @Override protected Tree createValue() { throw new RuntimeException("should not get here"); diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java index 78e8037880d..763f6930b13 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.spi.security; import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; import org.apache.jackrabbit.oak.spi.commit.CommitHook; @@ -391,10 +392,10 @@ public ConfigurationParameters getParameters() { @Test public void testGetMonitors() { StatisticsProvider statisticsProvider = StatisticsProvider.NOOP; - assertTrue(Iterables.isEmpty(compositeConfiguration.getMonitors(statisticsProvider))); + assertTrue(IterableUtils.isEmpty(compositeConfiguration.getMonitors(statisticsProvider))); addConfiguration(new SecurityConfiguration.Default()); - assertTrue(Iterables.isEmpty(compositeConfiguration.getMonitors(statisticsProvider))); + assertTrue(IterableUtils.isEmpty(compositeConfiguration.getMonitors(statisticsProvider))); Monitor monitor = mock(LoginModuleMonitor.class); SecurityConfiguration withMonitors = new SecurityConfiguration.Default() { diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java index 2f434ce7773..182e02a02b0 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java @@ -21,6 +21,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; @@ -368,12 +369,12 @@ public void testGetPrivilegeNamesWithAggregation() { @Test public void testGetAggregatedPrivilegeNamesEmpty() { - assertTrue(Iterables.isEmpty(bitsProvider.getAggregatedPrivilegeNames())); + assertTrue(IterableUtils.isEmpty(bitsProvider.getAggregatedPrivilegeNames())); } @Test public void testGetAggregatedPrivilegeNamesEmptyArray() { - assertTrue(Iterables.isEmpty(bitsProvider.getAggregatedPrivilegeNames())); + assertTrue(IterableUtils.isEmpty(bitsProvider.getAggregatedPrivilegeNames())); } @Test @@ -454,7 +455,7 @@ public void testGetAggregatedPrivilegeNamesNonExistingTree() { when(privTree.getChild(KNOWN_PRIV_NAME)).thenReturn(pTree); Iterable result = bitsProvider.getAggregatedPrivilegeNames(KNOWN_PRIV_NAME); - assertTrue(Iterables.isEmpty(result)); + assertTrue(IterableUtils.isEmpty(result)); } @Test From 4a7d2cfc95ba6a92ba435e455582b28dcfa74556 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Thu, 23 Jan 2025 20:17:14 +0530 Subject: [PATCH 2/3] OAK-11427 : fixed import issue --- .../apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java index cb600d98381..1a252cc4095 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java @@ -179,7 +179,7 @@ public void testGetMixinTypeNamesPresentNotAccessible() throws Exception { try (ContentSession cs = login(new GuestCredentials())) { Root guestRoot = cs.getLatestRoot(); assertTrue(IterableUtils.isEmpty(TreeUtil.getMixinTypeNames(guestRoot.getTree(path)))); - assertTrue(IterableUtils.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue() { + assertTrue(Iterables.elementsEqual(expected, TreeUtil.getMixinTypeNames(guestRoot.getTree(path), new LazyValue() { @Override protected Tree createValue() { return testTree; From e5cc56fb74baa58169dc9407faed996f7a22b7c5 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Thu, 23 Jan 2025 22:04:35 +0530 Subject: [PATCH 3/3] OAK-11427 : used commons-collections4 IterableUtils.isEmpty --- .../SyncHandlerMappingTrackerTest.java | 3 +- .../ldap/impl/LdapIdentityProviderTest.java | 2 +- .../authorization/cug/impl/NestedCugHook.java | 3 +- .../PrincipalPolicyValidatorProvider.java | 3 +- .../impl/PrincipalPolicyImporterTest.java | 3 +- .../commons/collections/IterableUtils.java | 48 -------------- .../collections/IterableUtilsTest.java | 65 ------------------- .../plugins/nodetype/TypeRegistration.java | 2 +- .../accesscontrol/AccessControlValidator.java | 2 +- .../property/AsyncPropertyIndexTest.java | 4 +- .../oak/plugins/tree/impl/TreeUtilTest.java | 2 +- .../oak/jcr/observation/EventFactory.java | 2 +- .../LuceneJournalPropertyBuilderTest.java | 2 +- .../plugins/index/search/IndexDefinition.java | 2 +- oak-security-spi/pom.xml | 4 ++ .../privilege/PrivilegeBitsProvider.java | 2 +- .../oak/plugins/tree/TreeUtilTest.java | 2 +- .../security/CompositeConfigurationTest.java | 2 +- .../privilege/PrivilegeBitsProviderTest.java | 2 +- 19 files changed, 21 insertions(+), 134 deletions(-) delete mode 100644 oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java delete mode 100644 oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java index d5eac6dd834..8e07d21474e 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java @@ -16,8 +16,7 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping; import org.junit.Before; diff --git a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java index 9887a750445..94ab7551841 100644 --- a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java +++ b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java @@ -17,9 +17,9 @@ package org.apache.jackrabbit.oak.security.authentication.ldap.impl; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; diff --git a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java index d3901181102..fb5dd05539e 100644 --- a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java +++ b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/NestedCugHook.java @@ -20,11 +20,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; + +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.PostValidationHook; diff --git a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java index 8dfa07f90a9..6ff2dcddc93 100644 --- a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java +++ b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyValidatorProvider.java @@ -16,7 +16,7 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -26,7 +26,6 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.StringUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.conditions.Validate; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate; diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java index d63ec6f8077..e1cd90658c9 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporterTest.java @@ -16,11 +16,10 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration; diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java deleted file mode 100644 index ad88546c762..00000000000 --- a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.jackrabbit.oak.commons.collections; - -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -/** - * Utility methods for {@link Iterable} conversions. - */ -public class IterableUtils { - - private IterableUtils() { - // no instances for you - } - - /** - * Checks if an iterable is empty. - * - * @param iterable the iterable to check, must not be {@code null} - * @param the type of elements in the iterable - * @return {@code true} if the iterable is empty, {@code false} otherwise - * @throws NullPointerException if the iterable is {@code null} - */ - public static boolean isEmpty(@NotNull Iterable iterable) { - if (iterable instanceof Collection) { - return ((Collection) iterable).isEmpty(); - } - return StreamUtils.toStream(iterable).findAny().isEmpty(); - } -} diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java deleted file mode 100644 index 630f90a3141..00000000000 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.jackrabbit.oak.commons.collections; - - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; - -/** - * Unit tests for the {@link IterableUtils} class. - *

- * This class contains test cases to verify the functionality of the methods - * in the {@link IterableUtils} class. - */ -public class IterableUtilsTest { - - @Test - public void testIsEmptyWithEmptyList() { - List emptyList = Collections.emptyList(); - Assert.assertTrue(IterableUtils.isEmpty(emptyList)); - } - - @Test - public void testIsEmptyWithNonEmptyList() { - List nonEmptyList = List.of("one", "two", "three"); - Assert.assertFalse(IterableUtils.isEmpty(nonEmptyList)); - } - - @Test - public void testIsEmptyWithEmptyIterable() { - Iterable emptyIterable = Collections::emptyIterator; - Assert.assertTrue(IterableUtils.isEmpty(emptyIterable)); - } - - @Test - public void testIsEmptyWithNonEmptyIterable() { - Iterable nonEmptyIterable = List.of("one", "two", "three"); - Assert.assertFalse(IterableUtils.isEmpty(nonEmptyIterable)); - } - - @Test - public void testIsEmptyWithNullIterable() { - Assert.assertThrows(NullPointerException.class, () -> IterableUtils.isEmpty(null)); - } - -} \ No newline at end of file diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java index 133bc242994..6346e6e6d04 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java @@ -65,9 +65,9 @@ import java.util.List; import java.util.Set; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.ListUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java index 5aad767b524..15e661660e4 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java @@ -25,6 +25,7 @@ import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; +import org.apache.commons.collections4.IterableUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; @@ -32,7 +33,6 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate; import org.apache.jackrabbit.oak.plugins.tree.TreeConstants; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java index 32c67cf583a..3b04e2d049c 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java @@ -31,7 +31,7 @@ import java.util.Arrays; import java.util.Set; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate; import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider; @@ -51,8 +51,6 @@ import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.junit.Test; -import org.apache.jackrabbit.guava.common.collect.Iterables; - /** * Test the asynchronous reindexing ability of an synchronous index */ diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java index 1a252cc4095..445e5082739 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/TreeUtilTest.java @@ -16,6 +16,7 @@ */ package org.apache.jackrabbit.oak.plugins.tree.impl; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.AbstractSecurityTest; @@ -25,7 +26,6 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.LazyValue; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.junit.Test; diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java index f8409633f74..d7f5200e555 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFactory.java @@ -34,11 +34,11 @@ import javax.jcr.Value; import javax.jcr.observation.Event; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.api.observation.JackrabbitEvent; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider; import org.apache.jackrabbit.oak.commons.PathUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java index c58ec52925d..813e3e6825b 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneJournalPropertyBuilderTest.java @@ -19,10 +19,10 @@ package org.apache.jackrabbit.oak.plugins.index.lucene.hybrid; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.HashMultimap; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Multimap; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.junit.Test; import static org.hamcrest.Matchers.containsInAnyOrder; diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java index f3797528ccd..b6ebdd81b17 100644 --- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java +++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java @@ -18,6 +18,7 @@ */ package org.apache.jackrabbit.oak.plugins.index.search; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.IllegalRepositoryStateException; @@ -26,7 +27,6 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; diff --git a/oak-security-spi/pom.xml b/oak-security-spi/pom.xml index c07b183f491..ce95515cfde 100644 --- a/oak-security-spi/pom.xml +++ b/oak-security-spi/pom.xml @@ -180,6 +180,10 @@ test-jar test + + org.apache.commons + commons-collections4 + diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java index 02c92e13f79..785b206a914 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java @@ -27,13 +27,13 @@ import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.FluentIterable; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.namepath.NameMapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java index ebea77b6777..18b00b7f681 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/plugins/tree/TreeUtilTest.java @@ -16,6 +16,7 @@ */ package org.apache.jackrabbit.oak.plugins.tree; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.PropertyState; @@ -24,7 +25,6 @@ import org.apache.jackrabbit.oak.commons.LazyValue; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.UUIDUtils; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.junit.Test; diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java index 763f6930b13..b3fa9a6f31d 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java @@ -16,8 +16,8 @@ */ package org.apache.jackrabbit.oak.spi.security; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; import org.apache.jackrabbit.oak.spi.commit.CommitHook; diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java index 182e02a02b0..f891ad46019 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java @@ -16,12 +16,12 @@ */ package org.apache.jackrabbit.oak.spi.security.privilege; +import org.apache.commons.collections4.IterableUtils; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; -import org.apache.jackrabbit.oak.commons.collections.IterableUtils; import org.apache.jackrabbit.oak.commons.collections.SetUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;