Skip to content

Commit 7b252c2

Browse files
authored
OAK-11387: Extract ListUtils from CollectionUtils (#1983)
* OAK-11387: Extract ListUtils from CollectionUtils * OAK-11387: Extract ListUtils from CollectionUtils - add class Javadoc
1 parent fe9c04c commit 7b252c2

File tree

116 files changed

+558
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+558
-477
lines changed

oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/DynamicGroupsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.jackrabbit.api.security.user.User;
2424
import org.apache.jackrabbit.api.security.user.UserManager;
2525
import org.apache.jackrabbit.oak.api.Tree;
26-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
26+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
2727
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup;
2828
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity;
2929
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityProvider;
@@ -292,7 +292,7 @@ public void testCrossIDPMembership() throws Exception {
292292
UserManager um = getUserManager(r);
293293
PrincipalManager pm = getPrincipalManager(r);
294294

295-
List<ExternalIdentityRef> declaredGroupRefs = CollectionUtils.toList(previouslySyncedUser.getDeclaredGroups());
295+
List<ExternalIdentityRef> declaredGroupRefs = ListUtils.toList(previouslySyncedUser.getDeclaredGroups());
296296
assertTrue(declaredGroupRefs.size() > 1);
297297

298298
String groupId = declaredGroupRefs.get(0).getId();

oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/DynamicGroupValidatorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.jackrabbit.oak.api.Tree;
2727
import org.apache.jackrabbit.oak.api.Type;
2828
import org.apache.jackrabbit.oak.commons.PathUtils;
29-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
29+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
3030
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
3131
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
3232
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -268,7 +268,7 @@ public void testModifyMembersPropertyLocalGroup() throws Exception {
268268

269269
Tree groupTree = r.getTree(localGroup.getPath());
270270
Tree userTree = r.getTree(userManager.getAuthorizable(USER_ID).getPath());
271-
List<String> members = CollectionUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
271+
List<String> members = ListUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
272272
members.add(userTree.getProperty(JCR_UUID).getValue(Type.STRING));
273273
groupTree.setProperty(REP_MEMBERS, members, Type.WEAKREFERENCES);
274274
r.commit();
@@ -300,7 +300,7 @@ public void testModifyMembersPropertyRemove() throws Exception {
300300
r.commit();
301301

302302
Tree groupTree = r.getTree(localGroup.getPath());
303-
List<String> members = CollectionUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
303+
List<String> members = ListUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
304304
members.remove(1);
305305
groupTree.setProperty(REP_MEMBERS, members, Type.WEAKREFERENCES);
306306
r.commit();
@@ -318,7 +318,7 @@ public void testModifyMembersPropertyAdd() throws Exception {
318318

319319
Tree groupTree = r.getTree(localGroup.getPath());
320320
Tree userTree = r.getTree(userManager.getAuthorizable(USER_ID).getPath());
321-
List<String> members = CollectionUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
321+
List<String> members = ListUtils.toList(groupTree.getProperty(REP_MEMBERS).getValue(Type.STRINGS));
322322
members.add(userTree.getProperty(JCR_UUID).getValue(Type.STRING));
323323
groupTree.setProperty(REP_MEMBERS, members, Type.WEAKREFERENCES);
324324
try {

oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.jackrabbit.oak.api.Tree;
2929
import org.apache.jackrabbit.oak.commons.PathUtils;
3030
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
31+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
3132
import org.apache.jackrabbit.oak.commons.collections.StreamUtils;
3233
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
3334
import org.apache.jackrabbit.oak.plugins.tree.TreeAware;
@@ -586,7 +587,7 @@ public Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, i
586587
return in.iterator();
587588
}
588589
};
589-
List<Principal> out = CollectionUtils.toList(p.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1));
590+
List<Principal> out = ListUtils.toList(p.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1));
590591
Collections.sort(in, Comparator.comparing(Principal::getName));
591592
assertEquals(in, out);
592593
}

oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManagerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.jackrabbit.oak.api.Root;
2424
import org.apache.jackrabbit.oak.api.Tree;
2525
import org.apache.jackrabbit.oak.commons.PathUtils;
26-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
26+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
2727
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
2828
import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants;
2929
import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
@@ -554,7 +554,7 @@ public void testGetEffectivePrincipalsEmptyPaths() throws Exception {
554554
Iterator<AccessControlPolicy> effective = acMgr.getEffectivePolicies(principals, new String[0]);
555555
AccessControlPolicy[] expected = acMgr.getEffectivePolicies(principals);
556556

557-
assertArrayEquals(expected, (CollectionUtils.toList(effective).toArray()));
557+
assertArrayEquals(expected, (ListUtils.toList(effective).toArray()));
558558
}
559559

560560
@Test
@@ -567,7 +567,7 @@ public void testGetEffectivePrincipalsReadablePaths() throws Exception {
567567
String[] paths = readablePaths.stream().map(oakPath -> namePathMapper.getJcrPath(oakPath)).distinct().toArray(String[]::new);
568568
assertEquals(3, paths.length);
569569

570-
List<AccessControlPolicy> effective = CollectionUtils.toList(acMgr.getEffectivePolicies(Collections.singleton(validPrincipal), paths));
570+
List<AccessControlPolicy> effective = ListUtils.toList(acMgr.getEffectivePolicies(Collections.singleton(validPrincipal), paths));
571571

572572
assertEquals(1, effective.size());
573573
assertEquals(ReadPolicy.INSTANCE, effective.get(0));

oak-benchmarks-lucene/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.apache.jackrabbit.oak.Oak;
4949
import org.apache.jackrabbit.oak.api.Type;
5050
import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
51-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
51+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
5252
import org.apache.jackrabbit.oak.fixture.JcrCreator;
5353
import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture;
5454
import org.apache.jackrabbit.oak.fixture.RepositoryFixture;
@@ -512,7 +512,7 @@ public void initialize(@NotNull NodeBuilder builder) {
512512
if (nodetype.exists()) {
513513
List<String> nodetypes = new ArrayList<>();
514514
if (nodetype.hasProperty(DECLARING_NODE_TYPES)){
515-
nodetypes = CollectionUtils.toList(nodetype.getProperty(DECLARING_NODE_TYPES).getValue(Type.STRINGS));
515+
nodetypes = ListUtils.toList(nodetype.getProperty(DECLARING_NODE_TYPES).getValue(Type.STRINGS));
516516
}
517517

518518
if (nodetypes.isEmpty()) {

oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.jackrabbit.core.data.util.NamedThreadFactory;
5252
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
5353
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
54+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
5455
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordDownloadOptions;
5556
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordUpload;
5657
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordUploadException;
@@ -1125,7 +1126,7 @@ private boolean loadBatch() {
11251126
return false;
11261127
}
11271128

1128-
List<S3ObjectSummary> listing = CollectionUtils.toList(
1129+
List<S3ObjectSummary> listing = ListUtils.toList(
11291130
filter(prevObjectListing.getObjectSummaries(),
11301131
input -> !input.getKey().startsWith(META_KEY_PREFIX)));
11311132

oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.apache.jackrabbit.guava.common.base.Stopwatch;
3838
import org.apache.jackrabbit.guava.common.io.Files;
3939
import org.apache.jackrabbit.core.data.DataRecord;
40-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
40+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
4141
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
4242
import org.apache.jackrabbit.oak.commons.io.BurnOnCloseFileIterator;
4343
import org.apache.jackrabbit.oak.commons.io.FileLineDifferenceIterator;
@@ -268,7 +268,7 @@ private void globalMerge() throws IOException {
268268
Iterable<DataRecord> refRecords = datastore.getAllMetadataRecords(fileNamePrefix);
269269

270270
// Download all the corresponding files for the records
271-
List<File> refFiles = CollectionUtils.toList(transform(refRecords, input -> {
271+
List<File> refFiles = ListUtils.toList(transform(refRecords, input -> {
272272
InputStream inputStream = null;
273273
try {
274274
inputStream = input.getStream();

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/ActiveDeletionTrackerStoreTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.jackrabbit.guava.common.base.Strings;
3333
import org.apache.jackrabbit.oak.commons.FileIOUtils;
3434
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
35+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
3536
import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore;
3637
import org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker.ActiveDeletionTracker;
3738
import org.junit.After;
@@ -117,7 +118,7 @@ public void filter() throws Exception {
117118
File toFilter = create(range(7, 10), folder);
118119
Iterator<String> filtered = tracker.filter(toFilter);
119120

120-
assertTrue("More elements after filtering", CollectionUtils.toList(filtered).isEmpty());
121+
assertTrue("More elements after filtering", ListUtils.toList(filtered).isEmpty());
121122
}
122123

123124
@Test
@@ -127,7 +128,7 @@ public void noFilter() throws Exception {
127128
File toFilterFile = create(toFilter, folder);
128129
Iterator<String> filtered = tracker.filter(toFilterFile);
129130

130-
assertEquals("Incorrect elements after filtering", range(0, 4), CollectionUtils.toList(filtered));
131+
assertEquals("Incorrect elements after filtering", range(0, 4), ListUtils.toList(filtered));
131132
}
132133

133134
@Test
@@ -138,7 +139,7 @@ public void filterWithExtraElements() throws Exception {
138139
Iterator<String> filtered = tracker.filter(toFilterFile);
139140

140141
assertEquals("Incorrect elements after filtering",
141-
range(0, 4), CollectionUtils.toList(filtered));
142+
range(0, 4), ListUtils.toList(filtered));
142143
}
143144

144145
@Test

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.jackrabbit.core.data.DataStore;
3838
import org.apache.jackrabbit.core.data.DataStoreException;
3939
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
40+
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
4041
import org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob;
4142
import org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest;
4243
import org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream;
@@ -169,7 +170,7 @@ public void testGetAllChunks() throws Exception{
169170
DataIdentifier d20 = new DataIdentifier("d-20");
170171
DataIdentifier d30 = new DataIdentifier("d-30");
171172
List<DataIdentifier> dis = List.of(d10, d20, d30);
172-
List<DataRecord> recs = CollectionUtils.toList(
173+
List<DataRecord> recs = ListUtils.toList(
173174
Iterables.transform(dis, input -> new TimeDataRecord(input)));
174175
OakFileDataStore mockedDS = mock(OakFileDataStore.class);
175176
when(mockedDS.getAllRecords()).thenReturn(recs.iterator());

oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.jackrabbit.oak.commons.collections;
2020

2121
import java.util.ArrayDeque;
22-
import java.util.ArrayList;
2322
import java.util.Arrays;
2423
import java.util.Collections;
2524
import java.util.HashMap;
@@ -28,8 +27,6 @@
2827
import java.util.Iterator;
2928
import java.util.LinkedHashMap;
3029
import java.util.LinkedHashSet;
31-
import java.util.LinkedList;
32-
import java.util.List;
3330
import java.util.Map;
3431
import java.util.Objects;
3532
import java.util.Properties;
@@ -38,7 +35,6 @@
3835
import java.util.concurrent.ConcurrentHashMap;
3936
import java.util.function.Predicate;
4037
import java.util.stream.Collectors;
41-
import java.util.stream.IntStream;
4238
import java.util.stream.Stream;
4339

4440
import org.jetbrains.annotations.NotNull;
@@ -56,79 +52,6 @@ private CollectionUtils() {
5652
// no instances for you
5753
}
5854

59-
/**
60-
* Convert an iterable to a list. The returning list is mutable and supports all optional operations.
61-
* @param iterable the iterable to convert
62-
* @return the list
63-
* @param <T> the type of the elements
64-
*/
65-
@NotNull
66-
public static <T> List<T> toList(@NotNull final Iterable<? extends T> iterable) {
67-
Objects.requireNonNull(iterable);
68-
List<T> result = new ArrayList<>();
69-
iterable.forEach(result::add);
70-
return result;
71-
}
72-
73-
/**
74-
* Convert an iterable to a {@link java.util.LinkedList}. The returning LinkedList is mutable and supports all optional operations.
75-
* @param iterable the iterator to convert
76-
* @return the LinkedList
77-
* @param <T> the type of the elements
78-
*/
79-
@NotNull
80-
public static <T> List<T> toLinkedList(final Iterable<T> iterable) {
81-
Objects.requireNonNull(iterable);
82-
List<T> result = new LinkedList<>();
83-
iterable.forEach(result::add);
84-
return result;
85-
}
86-
87-
/**
88-
* Convert an iterator to a list. The returning list is mutable and supports all optional operations.
89-
* @param iterator the iterator to convert
90-
* @return the list
91-
* @param <T> the type of the elements
92-
*/
93-
@NotNull
94-
public static <T> List<T> toList(final Iterator<? extends T> iterator) {
95-
Objects.requireNonNull(iterator);
96-
List<T> result = new ArrayList<>();
97-
iterator.forEachRemaining(result::add);
98-
return result;
99-
}
100-
101-
/**
102-
* Split a list into partitions of a given size.
103-
*
104-
* @param list the list to partition
105-
* @param n the size of partitions
106-
* @return a list of partitions. The resulting partitions aren’t a view of the main List, so any changes happening to the main List won’t affect the partitions.
107-
* @param <T> the type of the elements
108-
*/
109-
@NotNull
110-
public static <T> List<List<T>> partitionList(final List<T> list, final int n) {
111-
Objects.requireNonNull(list);
112-
return IntStream.range(0, list.size())
113-
.filter(i -> i % n == 0)
114-
.mapToObj(i -> list.subList(i, Math.min(i + n, list.size())))
115-
.collect(Collectors.toList());
116-
}
117-
118-
/**
119-
* Returns a new list containing the elements of the specified list in reverse order.
120-
*
121-
* @param <T> the type of elements in the list
122-
* @param l the list to be reversed, must not be null
123-
* @return a new list containing the elements of the specified list in reverse order
124-
* @throws NullPointerException if the list is null
125-
*/
126-
@NotNull
127-
public static <T> List<T> reverse(final List<T> l) {
128-
Objects.requireNonNull(l);
129-
return IntStream.range(0, l.size()).map(i -> l.size() - 1- i).mapToObj(l::get).collect(Collectors.toList());
130-
}
131-
13255
/**
13356
* Convert an iterable to a set. The returning set is mutable and supports all optional operations.
13457
* @param iterable the iterable to convert

0 commit comments

Comments
 (0)