Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Sets;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy;
import org.apache.jackrabbit.oak.api.ContentSession;
Expand Down Expand Up @@ -585,7 +584,7 @@ public void testGetEffectivePrincipalDistributed() throws Exception {
AccessControlPolicy[] testgroupEffective = cugAccessControlManager.getEffectivePolicies(Set.of(getTestGroupPrincipal()));
assertEquals(2, testgroupEffective.length);

assertTrue(Sets.intersection(Set.of(everyoneEffective), Set.of(testgroupEffective)).isEmpty());
assertTrue(CollectionUtils.intersection(Set.of(everyoneEffective), Set.of(testgroupEffective)).isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@ public static <T> Set<T> union(@NotNull final Set<T> s1, @NotNull final Set<T> s
return Stream.concat(s1.stream(), s2.stream()).collect(Collectors.toSet());
}

/**
* Returns a new set containing the intersection of the two specified sets.
* The intersection of two sets is a set containing only the elements that are present in both sets.
*
* @param <T> the type of elements in the sets
* @param s1 the first set, must not be null
* @param s2 the second set, must not be null
* @return a new set containing the intersection of the two specified sets
* @throws NullPointerException if either of the sets is null
*/
@NotNull
public static <T> Set<T> intersection(@NotNull final Set<T> s1, @NotNull final Set<T> s2) {
Objects.requireNonNull(s1);
Objects.requireNonNull(s2);
return s1.stream().filter(s2::contains).collect(Collectors.toSet());
}

/**
* Convert an iterable to a {@link java.util.ArrayDeque}.
* The returning array deque is mutable and supports all optional operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,57 @@ public void testUnionWithOverlappingSets() {
Assert.assertEquals(expected, CollectionUtils.union(set1, set2));
}

@Test
public void testIntersectionWithNonEmptySets() {
final Set<String> set1 = Set.of("a", "b", "c");
final Set<String> set2 = Set.of("b", "c", "d");

final Set<String> result = CollectionUtils.intersection(set1, set2);

final Set<String> expected = Set.of("b", "c");
Assert.assertEquals(expected, result);
}

@Test
public void testIntersectionWithEmptySet() {
final Set<String> set1 = Set.of("a", "b", "c");
final Set<String> set2 = Set.of();

Assert.assertEquals(Collections.EMPTY_SET, CollectionUtils.intersection(set1, set2));
}

@Test
public void testIntersectionWithBothEmptySets() {
final Set<String> set1 = new HashSet<>();
final Set<String> set2 = new HashSet<>();

Assert.assertEquals(Collections.EMPTY_SET, CollectionUtils.intersection(set1, set2));
}

@Test(expected = NullPointerException.class)
public void testIntersectionWithNullFirstSet() {
final Set<String> set1 = null;
final Set<String> set2 = Set.of("a", "b", "c");

CollectionUtils.intersection(set1, set2);
}

@Test(expected = NullPointerException.class)
public void testIntersectionWithNullSecondSet() {
final Set<String> set1 = Set.of("a", "b", "c");
final Set<String> set2 = null;

CollectionUtils.intersection(set1, set2);
}

@Test
public void testIntersectionWithNoCommonElements() {
final Set<String> set1 = Set.of("a", "b", "c");
final Set<String> set2 = Set.of("d", "e", "f");

Assert.assertEquals(Collections.EMPTY_SET, CollectionUtils.intersection(set1, set2));
}

@Test
public void iteratorToIIteratable() {
Iterator<String> iterator = List.of("a", "b", "c").iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private static void mergeChange(@NotNull NodeBuilder parent, @NotNull PropertySt
Set<String> ourMembers = CollectionUtils.toSet(ours.getValue(Type.STRINGS));

// merge ours and theirs to a de-duplicated set
Set<String> combined = new LinkedHashSet<>(Sets.intersection(ourMembers, theirMembers));
Set<String> combined = new LinkedHashSet<>(CollectionUtils.intersection(ourMembers, theirMembers));
for (String m : Sets.difference(ourMembers, theirMembers)) {
if (!base.contains(m)) {
combined.add(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ private boolean expected(Set<String> check, Set<String> supported1, Set<String>
if (type == CompositionType.OR) {
return Sets.difference(Sets.difference(check, granted1), granted2).isEmpty();
} else {
Set<String> f1 = Sets.intersection(supported1, check);
Set<String> f1 = CollectionUtils.intersection(supported1, check);
boolean hasf1 = granted1.containsAll(f1);
Set<String> f2 = Sets.intersection(supported2, check);
Set<String> f2 = CollectionUtils.intersection(supported2, check);
boolean hasf2 = granted2.containsAll(f2);
return hasf1 && hasf2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.jackrabbit.oak.explorer;

import static org.apache.jackrabbit.guava.common.collect.Sets.intersection;
import static org.apache.jackrabbit.guava.common.escape.Escapers.builder;
import static java.util.Collections.sort;
import static javax.jcr.PropertyType.BINARY;
Expand Down Expand Up @@ -413,7 +412,7 @@ void printTarInfo(String file) {
}
}

Set<UUID> inMem = intersection(backend.getReferencedSegmentIds(), uuids);
Set<UUID> inMem = CollectionUtils.intersection(backend.getReferencedSegmentIds(), uuids);
if (!inMem.isEmpty()) {
sb.append("In Memory segment references: ");
sb.append(newline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.collect.Sets;
import joptsimple.OptionException;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -753,7 +751,7 @@ private void testConsistency(File dump, Data data, boolean verbose, boolean verb
if (!markOnly) {
// Verbose would have paths as well as ids changed but normally only DocumentNS would have paths suffixed
assertFileEquals(dump, "gccand-", verbose ?
encodedIdsAndPath(verboseRootPath ? Sets.intersection(data.addedSubset, data.missingDataStore) :
encodedIdsAndPath(verboseRootPath ? CollectionUtils.intersection(data.addedSubset, data.missingDataStore) :
data.missingDataStore, blobFixture.getType(), data.idToPath, true) :
(storeFixture instanceof StoreFixture.MongoStoreFixture) ?
encodedIdsAndPath(data.missingDataStore, blobFixture.getType(), data.idToPath, false) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.jackrabbit.oak.segment;

import static org.apache.jackrabbit.guava.common.collect.Sets.intersection;
import static org.apache.jackrabbit.guava.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
Expand All @@ -38,6 +37,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;

import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation;
import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration;
import org.apache.jackrabbit.oak.segment.memory.MemoryStore;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void testFlush() throws ExecutionException, InterruptedException, IOExcep
assertEquals(rootId, res5.get());
assertEquals(rootId, res6.get());
assertEquals(3, map2.size());
assertTrue(intersection(new HashSet<>(map1.values()), new HashSet<>(map2.values())).isEmpty());
assertTrue(CollectionUtils.intersection(new HashSet<>(map1.values()), new HashSet<>(map2.values())).isEmpty());
}

@Test
Expand Down Expand Up @@ -209,7 +209,7 @@ public void testCompaction() throws ExecutionException, InterruptedException, IO
assertEquals(rootId, res8.get());
assertEquals(rootId, res9.get());
assertEquals(3, map3.size());
assertTrue(intersection(new HashSet<>(map1.values()), new HashSet<>(map3.values())).isEmpty());
assertTrue(CollectionUtils.intersection(new HashSet<>(map1.values()), new HashSet<>(map3.values())).isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
import java.util.concurrent.locks.ReadWriteLock;

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Sets;

import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
Expand Down Expand Up @@ -752,7 +751,7 @@ private void checkForConflicts() throws CommitFailedException {
Set<Revision> collisions = new HashSet<>(doc.getLocalMap(COLLISIONS).keySet());
Set<Revision> commits = new HashSet<>();
Iterables.transform(b.getCommits(), Revision::asTrunkRevision).forEach(commits::add);
Set<Revision> conflicts = Sets.intersection(collisions, commits);
Set<Revision> conflicts = CollectionUtils.intersection(collisions, commits);
if (!conflicts.isEmpty()) {
throw new CommitFailedException(STATE, 2,
"Conflicting concurrent change on branch commits " + conflicts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ protected <T extends Document> Iterable<T> queryAsIterable(final Collection<T> c
final List<String> excludeKeyPatterns, final List<QueryCondition> conditions, final int limit, final String sortBy) {

final RDBTableMetaData tmd = getTable(collection);
Set<String> allowedProps = Sets.intersection(INDEXEDPROPERTIES, tmd.getColumnProperties());
Set<String> allowedProps = CollectionUtils.intersection(INDEXEDPROPERTIES, tmd.getColumnProperties());
for (QueryCondition cond : conditions) {
if (!allowedProps.contains(cond.getPropertyName())) {
String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond
Expand Down