Skip to content

Commit ae06fc4

Browse files
author
Rishabh Kumar
committed
OAK-11375 : made inplace changes and removed the util method
1 parent b306ddb commit ae06fc4

File tree

4 files changed

+9
-79
lines changed

4 files changed

+9
-79
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl;
1818

1919
import org.apache.jackrabbit.guava.common.collect.Iterables;
20-
import org.apache.jackrabbit.guava.common.collect.Maps;
2120
import org.apache.jackrabbit.api.security.user.User;
2221
import org.apache.jackrabbit.oak.api.Tree;
2322
import org.apache.jackrabbit.oak.commons.PathUtils;
24-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
2523
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
2624
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
2725
import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
@@ -56,6 +54,7 @@
5654
import java.util.Arrays;
5755
import java.util.List;
5856
import java.util.Map;
57+
import java.util.stream.Collectors;
5958

6059
import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_GLOB;
6160
import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_ITEM_NAMES;
@@ -139,13 +138,13 @@ private List<PropInfo> mockPropInfos(@Nullable String effectivePath, @NotNull S
139138
}
140139

141140
private List<PropInfo> mockPropInfos(@NotNull Map<String, String> restrictions, int propertyType) throws RepositoryException {
142-
return mockPropInfos(CollectionUtils.transformValues(restrictions, string -> {
141+
return mockPropInfos(restrictions.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> {
143142
try {
144-
return new Value[] {getValueFactory(root).createValue(string, propertyType)};
145-
} catch (ValueFormatException e) {
146-
throw new RuntimeException(e);
143+
return new Value[] {getValueFactory(root).createValue(e.getValue(), propertyType)};
144+
} catch (ValueFormatException ex) {
145+
throw new RuntimeException(ex);
147146
}
148-
}));
147+
})));
149148
}
150149

151150
private List<PropInfo> mockPropInfos(@NotNull Map<String, Value[]> restrictions) throws RepositoryException {

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Set;
3737
import java.util.TreeSet;
3838
import java.util.concurrent.ConcurrentHashMap;
39-
import java.util.function.Function;
4039
import java.util.function.Predicate;
4140
import java.util.stream.Collectors;
4241
import java.util.stream.IntStream;
@@ -487,27 +486,6 @@ public static <K,V> Map<K, V> filterEntries(final @NotNull Map<K, V> map, final
487486
.collect(LinkedHashMap::new, (m,e)->m.put(e.getKey(), e.getValue()), LinkedHashMap::putAll);
488487
}
489488

490-
/**
491-
* Create a new {@link Map} after transforming the values of the given map
492-
* based on the specified function.
493-
*
494-
* @param <K> the type of keys in the map
495-
* @param <V1> the type of original values in the map
496-
* @param <V2> the type of transformed values in the map
497-
* @param map the map whose values are to be transformed, must not be null
498-
* @param function the function to apply to the values, must not be null
499-
* @return a new map containing the same keys as the given map, but with values transformed by the specified function
500-
* @throws NullPointerException if the map or function is null
501-
*/
502-
@NotNull
503-
public static <K, V1, V2> Map<K, V2> transformValues(final @NotNull Map<K, V1> map, final @NotNull Function<? super V1, ? extends V2> function) {
504-
Objects.requireNonNull(map);
505-
Objects.requireNonNull(function);
506-
return map.entrySet()
507-
.stream() // using LinkedHashMap to maintain the order of previous map
508-
.collect(LinkedHashMap::new, (m, e)->m.put(e.getKey(), function.apply(e.getValue())), LinkedHashMap::putAll);
509-
}
510-
511489
/**
512490
* Convert an {@code Iterator} to an {@code Iterable}.
513491
* <p>

oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Properties;
3535
import java.util.Set;
3636
import java.util.TreeSet;
37-
import java.util.function.Function;
3837
import java.util.function.Predicate;
3938
import java.util.stream.Collectors;
4039
import java.util.stream.Stream;
@@ -767,50 +766,6 @@ public void testFilterEntriesNullPredicate() {
767766
Assert.assertThrows(NullPointerException.class, () -> CollectionUtils.filterEntries(map, null));
768767
}
769768

770-
@Test
771-
public void testTransformValues() {
772-
final Map<String, Integer> map = new HashMap<>();
773-
map.put("one", 1);
774-
map.put("two", 2);
775-
map.put("three", 3);
776-
777-
final Function<Integer, String> function = value -> "Number " + value;
778-
779-
final Map<String, String> result = CollectionUtils.transformValues(map, function);
780-
781-
Assert.assertEquals(3, result.size());
782-
Assert.assertEquals("Number 1", result.get("one"));
783-
Assert.assertEquals("Number 2", result.get("two"));
784-
Assert.assertEquals("Number 3", result.get("three"));
785-
}
786-
787-
@Test
788-
public void testTransformValuesEmptyMap() {
789-
final Map<String, Integer> map = new HashMap<>();
790-
final Function<Integer, String> function = value -> "Number " + value;
791-
792-
final Map<String, String> result = CollectionUtils.transformValues(map, function);
793-
794-
Assert.assertTrue(result.isEmpty());
795-
}
796-
797-
@Test
798-
public void testTransformValuesNullMap() {
799-
final Function<Integer, String> function = value -> "Number " + value;
800-
801-
Assert.assertThrows(NullPointerException.class, () -> CollectionUtils.transformValues(null, function));
802-
}
803-
804-
@Test
805-
public void testTransformValuesNullFunction() {
806-
final Map<String, Integer> map = new HashMap<>();
807-
map.put("one", 1);
808-
map.put("two", 2);
809-
map.put("three", 3);
810-
811-
Assert.assertThrows(NullPointerException.class, () -> CollectionUtils.transformValues(map, null));
812-
}
813-
814769
@Test
815770
public void ensureCapacity() {
816771
int capacity = CollectionUtils.ensureCapacity(8);

oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitBuilder.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
import java.util.LinkedHashMap;
2222
import java.util.Map;
2323
import java.util.Set;
24-
import java.util.stream.Collectors;
25-
26-
import org.apache.jackrabbit.guava.common.collect.Maps;
2724

2825
import org.apache.jackrabbit.oak.api.PropertyState;
29-
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
3026
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
3127
import org.apache.jackrabbit.oak.spi.state.NodeState;
3228
import org.jetbrains.annotations.NotNull;
@@ -270,7 +266,9 @@ Commit build(@NotNull Revision revision) {
270266
requireNonNull(revision);
271267

272268
Revision from = this.revision;
273-
Map<Path, UpdateOp> operations = CollectionUtils.transformValues(this.operations, op -> rewrite(op, from, revision));
269+
Map<Path, UpdateOp> operations = this.operations.entrySet()
270+
.stream()
271+
.collect(LinkedHashMap::new, (m,e)->m.put(e.getKey(), rewrite(e.getValue(), from, revision)), LinkedHashMap::putAll);
274272
return new Commit(nodeStore, revision, baseRevision, startRevisions,
275273
operations, addedNodes, removedNodes, nodesWithBinaries,
276274
bundledNodes);

0 commit comments

Comments
 (0)