Skip to content

Commit 9e33e09

Browse files
rishabhdaimRishabh Kumar
andauthored
OAK-11388 : extracted out Map methods from CollectionUtils (#1989)
* OAK-11388 : extracted out Map methods from CollectionUtils * OAK-11388 : removed closing of <p> --------- Co-authored-by: Rishabh Kumar <[email protected]>
1 parent 8017177 commit 9e33e09

File tree

25 files changed

+516
-434
lines changed

25 files changed

+516
-434
lines changed

oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.jackrabbit.oak.api.Tree;
2323
import org.apache.jackrabbit.oak.api.Type;
2424
import org.apache.jackrabbit.oak.commons.PathUtils;
25-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
25+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
2626
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
2727
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
2828
import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList;
@@ -153,7 +153,7 @@ public boolean addEntry(@NotNull Principal principal, @NotNull Privilege[] privi
153153

154154
String jcrNodePathName = getNamePathMapper().getJcrName(AccessControlConstants.REP_NODE_PATH);
155155
String path = extractPathFromRestrictions(restrictions, jcrNodePathName);
156-
Map<String, Value> filteredRestrictions = CollectionUtils.filterEntries(restrictions, entry -> !jcrNodePathName.equals(entry.getKey()));
156+
Map<String, Value> filteredRestrictions = MapUtils.filterEntries(restrictions, entry -> !jcrNodePathName.equals(entry.getKey()));
157157

158158
return addEntry(path, privileges, filteredRestrictions, (mvRestrictions == null) ? Collections.emptyMap() : mvRestrictions);
159159
}

oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureDataStoreUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.apache.commons.io.IOUtils;
3939
import org.apache.jackrabbit.core.data.DataStore;
4040
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
41-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
41+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
4242
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils;
4343
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.ConfigurableDataRecordAccessProvider;
4444
import org.jetbrains.annotations.NotNull;
@@ -109,7 +109,7 @@ public static Properties getAzureConfig() {
109109
IOUtils.closeQuietly(is);
110110
}
111111
props.putAll(getConfig());
112-
Map<String, String> filtered = CollectionUtils.filterEntries(CollectionUtils.fromProperties(props),
112+
Map<String, String> filtered = MapUtils.filterEntries(MapUtils.fromProperties(props),
113113
input -> !Strings.isNullOrEmpty(input.getValue()));
114114
props = new Properties();
115115
props.putAll(filtered);
@@ -119,7 +119,7 @@ public static Properties getAzureConfig() {
119119

120120
public static DataStore getAzureDataStore(Properties props, String homeDir) throws Exception {
121121
AzureDataStore ds = new AzureDataStore();
122-
PropertiesUtil.populate(ds, CollectionUtils.fromProperties(props), false);
122+
PropertiesUtil.populate(ds, MapUtils.fromProperties(props), false);
123123
ds.setProperties(props);
124124
ds.init(homeDir);
125125

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
import org.apache.jackrabbit.core.data.DataStoreException;
5151
import org.apache.jackrabbit.core.data.util.NamedThreadFactory;
5252
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
53-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
5453
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
54+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
5555
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordDownloadOptions;
5656
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordUpload;
5757
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordUploadException;
@@ -251,7 +251,7 @@ public void init() throws DataStoreException {
251251
LOG.error("Error ", e);
252252
Map<String, Object> filteredMap = new HashMap<>();
253253
if (properties != null) {
254-
filteredMap = CollectionUtils.filterKeys(Utils.asMap(properties),
254+
filteredMap = MapUtils.filterKeys(Utils.asMap(properties),
255255
input -> !input.equals(S3Constants.ACCESS_KEY) &&!input.equals(S3Constants.SECRET_KEY));
256256
}
257257
throw new DataStoreException("Could not initialize S3 from " + filteredMap, e);

oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.Map;
2525

26-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
26+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
2727
import org.apache.jackrabbit.oak.plugins.blob.AbstractSharedCachingDataStore;
2828
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
2929
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
@@ -78,7 +78,7 @@ public void testDefaultS3Implementation() throws IOException {
7878

7979
private void registerBlobStore() throws IOException {
8080
Map<String, Object> properties = new HashMap<>();
81-
properties.putAll(CollectionUtils.fromProperties(S3DataStoreUtils.getS3Config()));
81+
properties.putAll(MapUtils.fromProperties(S3DataStoreUtils.getS3Config()));
8282
properties.put("repository.home", folder.newFolder().getAbsolutePath());
8383
service = new S3DataStoreService();
8484
injectServices(service, context.bundleContext());

oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.apache.commons.io.IOUtils;
4545
import org.apache.jackrabbit.core.data.DataStore;
4646
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
47-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
47+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
4848
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils;
4949
import org.jetbrains.annotations.NotNull;
5050
import org.slf4j.Logger;
@@ -122,7 +122,7 @@ public static Properties getS3Config() {
122122
IOUtils.closeQuietly(is);
123123
}
124124
props.putAll(getConfig());
125-
Map<String, String> filtered = CollectionUtils.filterEntries(CollectionUtils.fromProperties(props),
125+
Map<String, String> filtered = MapUtils.filterEntries(MapUtils.fromProperties(props),
126126
input ->!Strings.isNullOrEmpty(input.getValue()));
127127
props = new Properties();
128128
props.putAll(filtered);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.jackrabbit.core.data.DataRecord;
2828
import org.apache.jackrabbit.core.data.DataStore;
2929
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
30-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
30+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
3131
import org.junit.After;
3232
import org.junit.Assert;
3333
import org.junit.Before;
@@ -62,7 +62,7 @@ protected DataStore createDataStore() throws RepositoryException {
6262
ds = new CachingFileDataStore();
6363
Map<String, ?> config = DataStoreUtils.getConfig();
6464
props.putAll(config);
65-
PropertiesUtil.populate(ds, CollectionUtils.fromProperties(props), false);
65+
PropertiesUtil.populate(ds, MapUtils.fromProperties(props), false);
6666
ds.setProperties(props);
6767
ds.init(dataStoreDir);
6868
} catch (Exception e) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.jackrabbit.core.data.DataStoreException;
2929
import org.apache.jackrabbit.core.data.FileDataStore;
3030
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
31-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
31+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
3232
import org.junit.Test;
3333
import org.slf4j.Logger;
3434
import org.slf4j.LoggerFactory;
@@ -76,7 +76,7 @@ public static DataStoreBlobStore getBlobStore() throws Exception {
7676

7777
public static Map<String, ?> getConfig() {
7878
Map<String, Object> result = new HashMap<>();
79-
for (Map.Entry<String, ?> e : CollectionUtils.fromProperties(System.getProperties()).entrySet()) {
79+
for (Map.Entry<String, ?> e : MapUtils.fromProperties(System.getProperties()).entrySet()) {
8080
String key = e.getKey();
8181
if (key.startsWith(DS_PROP_PREFIX) || key.startsWith(BS_PROP_PREFIX)) {
8282
key = key.substring(3); //length of bs.
@@ -107,7 +107,7 @@ public static CachingFileDataStore createCachingFDS(String path, String cachePat
107107
ds.setMinRecordLength(10);
108108
Map<String, ?> config = DataStoreUtils.getConfig();
109109
props.putAll(config);
110-
PropertiesUtil.populate(ds, CollectionUtils.fromProperties(props), false);
110+
PropertiesUtil.populate(ds, MapUtils.fromProperties(props), false);
111111
ds.setProperties(props);
112112
ds.init(cachePath);
113113
return ds;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.apache.jackrabbit.core.data.util.NamedThreadFactory;
4242
import org.apache.jackrabbit.oak.commons.FileIOUtils;
4343
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
44-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
44+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
4545
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
4646
import org.junit.After;
4747
import org.junit.Before;
@@ -88,7 +88,7 @@ protected DataStore createDataStore() {
8888
ds = new CachingFileDataStore();
8989
Map<String, ?> config = DataStoreUtils.getConfig();
9090
props.putAll(config);
91-
PropertiesUtil.populate(ds, CollectionUtils.fromProperties(props), false);
91+
PropertiesUtil.populate(ds, MapUtils.fromProperties(props), false);
9292
ds.setProperties(props);
9393
ds.init(dataStoreDir);
9494
} catch (Exception e) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.apache.jackrabbit.core.data.DataStoreException;
4444
import org.apache.jackrabbit.core.data.FileDataStore;
4545
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
46-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
46+
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
4747
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
4848
import org.apache.jackrabbit.oak.plugins.blob.SharedDataStore;
4949
import org.apache.jackrabbit.oak.plugins.blob.datastore.SharedDataStoreTest.FixtureHelper.DATA_STORE;
@@ -102,7 +102,7 @@ public void setup() throws Exception {
102102

103103
Properties props = new Properties();
104104
props.setProperty("fsBackendPath", folder.newFolder().getAbsolutePath());
105-
PropertiesUtil.populate(ds, CollectionUtils.fromProperties(props), false);
105+
PropertiesUtil.populate(ds, MapUtils.fromProperties(props), false);
106106
ds.setProperties(props);
107107
ds.init(folder.newFolder().getAbsolutePath());
108108
dataStore = ds;

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

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

2121
import java.util.ArrayDeque;
22-
import java.util.HashMap;
2322
import java.util.Iterator;
24-
import java.util.LinkedHashMap;
25-
import java.util.Map;
2623
import java.util.Objects;
27-
import java.util.Properties;
28-
import java.util.function.Predicate;
29-
import java.util.stream.Collectors;
3024

3125
import org.jetbrains.annotations.NotNull;
3226

@@ -58,110 +52,6 @@ public static <T> ArrayDeque<T> toArrayDeque(@NotNull Iterable<? extends T> iter
5852
return arrayDeque;
5953
}
6054

61-
/**
62-
* Creates a new, empty HashMap with expected capacity.
63-
* <p>
64-
* The returned map uses the default load factor of 0.75, and its capacity is
65-
* large enough to add expected number of elements without resizing.
66-
*
67-
* @param capacity the expected number of elements
68-
* @throws IllegalArgumentException if capacity is negative
69-
* @see SetUtils#newHashSet(int)
70-
* @see SetUtils#newLinkedHashSet(int)
71-
*/
72-
@NotNull
73-
public static <K, V> Map<K, V> newHashMap(final int capacity) {
74-
// make sure the Map does not need to be resized given the initial content
75-
return new HashMap<>(ensureCapacity(capacity));
76-
}
77-
78-
/**
79-
* Converts a {@link Properties} object to an unmodifiable {@link Map} with
80-
* string keys and values.
81-
*
82-
* @param properties the {@link Properties} object to convert, must not be null
83-
* @return an unmodifiable {@link Map} containing the same entries as the given {@link Properties} object
84-
* @throws NullPointerException if the properties parameter is null
85-
*/
86-
@NotNull
87-
public static Map<String, String> fromProperties(final @NotNull Properties properties) {
88-
Objects.requireNonNull(properties);
89-
return properties.entrySet()
90-
.stream()
91-
.collect(Collectors.toUnmodifiableMap(
92-
e -> String.valueOf(e.getKey()),
93-
e -> String.valueOf(e.getValue())));
94-
}
95-
96-
/**
97-
* Create a new {@link Map} after filtering the entries of the given map
98-
* based on the specified predicate applied to the keys.
99-
*
100-
* @param <K> the type of keys in the map
101-
* @param <V> the type of values in the map
102-
* @param map the map to filter, must not be null
103-
* @param predicate the predicate to apply to the keys, must not be null
104-
* @return a new map containing only the entries whose keys match the predicate
105-
* @throws NullPointerException if the map or predicate is null
106-
* @see CollectionUtils#filterValues(Map, Predicate)
107-
* @see CollectionUtils#filterEntries(Map, Predicate)
108-
*/
109-
@NotNull
110-
public static <K,V> Map<K, V> filterKeys(final @NotNull Map<K, V> map, final @NotNull Predicate<? super K> predicate) {
111-
Objects.requireNonNull(map);
112-
Objects.requireNonNull(predicate);
113-
return map.entrySet()
114-
.stream()
115-
.filter(e -> predicate.test(e.getKey())) // using LinkedHashMap to maintain the order of previous map
116-
.collect(LinkedHashMap::new, (m, e)->m.put(e.getKey(), e.getValue()), LinkedHashMap::putAll);
117-
}
118-
119-
/**
120-
* Create a new {@link Map} after filtering the entries of the given map
121-
* based on the specified predicate applied to the values.
122-
*
123-
* @param <K> the type of keys in the map
124-
* @param <V> the type of values in the map
125-
* @param map the map to filter, must not be null
126-
* @param predicate the predicate to apply to the values, must not be null
127-
* @return a new map containing only the entries whose values match the predicate
128-
* @throws NullPointerException if the map or predicate is null
129-
* @see CollectionUtils#filterKeys(Map, Predicate)
130-
* @see CollectionUtils#filterEntries(Map, Predicate)
131-
*/
132-
@NotNull
133-
public static <K,V> Map<K, V> filterValues(final @NotNull Map<K, V> map, final @NotNull Predicate<? super V> predicate) {
134-
Objects.requireNonNull(map);
135-
Objects.requireNonNull(predicate);
136-
return map.entrySet()
137-
.stream()
138-
.filter(e -> predicate.test(e.getValue())) // using LinkedHashMap to maintain the order of previous map
139-
.collect(LinkedHashMap::new, (m,e)->m.put(e.getKey(), e.getValue()), LinkedHashMap::putAll);
140-
}
141-
142-
/**
143-
* Create a new {@link Map} after filtering the entries of the given map
144-
* based on the specified predicate applied to the {@link java.util.Map.Entry}.
145-
*
146-
* @param <K> the type of keys in the map
147-
* @param <V> the type of values in the map
148-
* @param map the map to filter, must not be null
149-
* @param predicate the predicate to apply to the {@link java.util.Map.Entry}, must not be null
150-
* @return a new map containing only the entries whose values match the predicate
151-
* @throws NullPointerException if the map or predicate is null
152-
* @see CollectionUtils#filterKeys(Map, Predicate)
153-
* @see CollectionUtils#filterValues(Map, Predicate)
154-
*/
155-
@NotNull
156-
public static <K,V> Map<K, V> filterEntries(final @NotNull Map<K, V> map, final @NotNull Predicate<? super Map.Entry<K, V>> predicate) {
157-
Objects.requireNonNull(map);
158-
Objects.requireNonNull(predicate);
159-
return map.entrySet()
160-
.stream()
161-
.filter(predicate) // using LinkedHashMap to maintain the order of previous map
162-
.collect(LinkedHashMap::new, (m,e)->m.put(e.getKey(), e.getValue()), LinkedHashMap::putAll);
163-
}
164-
16555
/**
16656
* Convert an {@code Iterator} to an {@code Iterable}.
16757
* <p>

0 commit comments

Comments
 (0)