Skip to content

Commit b235154

Browse files
rishabhdaimRishabh Kumar
andauthored
OAK-11441 : removed usage of Guava Iterables.addAll (#2037)
* OAK-11441 : removed usage of Guava Iterables.addAll * OAK-11441 : removed usage of Guava Iterables.addAll with iterable.foreach() --------- Co-authored-by: Rishabh Kumar <diam@adobe.com>
1 parent ae033c1 commit b235154

File tree

18 files changed

+24
-38
lines changed

18 files changed

+24
-38
lines changed

oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private Set<String> collectEffectiveCandidates(@NotNull Root r, @NotNull Iterabl
367367
String path = eval.remove();
368368
Tree t = immutableRoot.getTree(path);
369369
if (PathUtils.denotesRoot(path)) {
370-
Iterables.addAll(eval, nestedCugPaths(t));
370+
nestedCugPaths(t).forEach(eval::add);
371371
}
372372
if (CugUtil.isSupportedPath(path, supportedPaths)) {
373373
Tree cug = CugUtil.getCug(t);
@@ -376,7 +376,7 @@ private Set<String> collectEffectiveCandidates(@NotNull Root r, @NotNull Iterabl
376376
if (!Collections.disjoint(SetUtils.toSet(principalNames), SetUtils.toSet(pNames.getValue(Type.STRINGS)))) {
377377
candidates.add(path);
378378
}
379-
Iterables.addAll(eval, nestedCugPaths(cug));
379+
nestedCugPaths(cug).forEach(eval::add);
380380
}
381381
}
382382
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void before() throws Exception {
7373
readablePaths = Iterators.cycle(Iterables.transform(paths, f -> getNamePathMapper().getJcrPath(f)));
7474
Set<String> childPaths = new HashSet<>();
7575
for (String path : paths) {
76-
Iterables.addAll(childPaths, Iterables.transform(root.getTree(path).getChildren(), tree -> getNamePathMapper().getJcrPath(tree.getPath())));
76+
Iterables.transform(root.getTree(path).getChildren(), tree -> getNamePathMapper().getJcrPath(tree.getPath())).forEach(childPaths::add);
7777
}
7878
readableChildPaths = Iterators.cycle(childPaths);
7979
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void before() throws Exception {
6464
readablePaths = Iterators.cycle(paths);
6565
Set<String> childPaths = new HashSet<>();
6666
for (String path : paths) {
67-
Iterables.addAll(childPaths, Iterables.transform(root.getTree(path).getChildren(), Tree::getPath));
67+
Iterables.transform(root.getTree(path).getChildren(), Tree::getPath).forEach(childPaths::add);
6868
}
6969
readableChildPaths = Iterators.cycle(childPaths);
7070

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/NodeCounterMBeanEstimator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.HashSet;
2323
import java.util.Set;
2424

25-
import org.apache.jackrabbit.guava.common.collect.Iterables;
2625
import org.apache.jackrabbit.oak.commons.PathUtils;
2726
import org.apache.jackrabbit.oak.plugins.index.counter.jmx.NodeCounter;
2827
import org.apache.jackrabbit.oak.spi.filter.PathFilter;
@@ -92,8 +91,8 @@ public void compute(String basePath, Set<String> indexPaths) {
9291
return;
9392
}
9493

95-
Iterables.addAll(includes, PathFilter.getStrings(idxState.getProperty(PROP_INCLUDED_PATHS), Set.of()));
96-
Iterables.addAll(excludes, PathFilter.getStrings(idxState.getProperty(PROP_EXCLUDED_PATHS), Set.of()));
94+
PathFilter.getStrings(idxState.getProperty(PROP_INCLUDED_PATHS), Set.of()).forEach(includes::add);
95+
PathFilter.getStrings(idxState.getProperty(PROP_EXCLUDED_PATHS), Set.of()).forEach(excludes::add);
9796
}
9897

9998
if (includes.isEmpty()) {

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/AbstractDecoratedNodeState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private PropertyState decorate(@Nullable final PropertyState property) {
9696
protected static PropertyState fixChildOrderPropertyState(NodeState nodeState, PropertyState propertyState) {
9797
if (propertyState != null && OAK_CHILD_ORDER.equals(propertyState.getName())) {
9898
final Collection<String> childNodeNames = new ArrayList<String>();
99-
Iterables.addAll(childNodeNames, nodeState.getChildNodeNames());
99+
nodeState.getChildNodeNames().forEach(childNodeNames::add);
100100
final Iterable<String> values = Iterables.filter(
101101
propertyState.getValue(Type.NAMES), x -> childNodeNames.contains(x));
102102
return PropertyStates.createProperty(OAK_CHILD_ORDER, values, Type.NAMES);

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.jetbrains.annotations.Nullable;
3030

3131
import static java.util.Objects.requireNonNull;
32-
import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll;
3332
import static org.apache.jackrabbit.guava.common.collect.Iterables.concat;
3433
import static org.apache.jackrabbit.guava.common.collect.Iterables.contains;
3534
import static org.apache.jackrabbit.JcrConstants.JCR_DEFAULTPRIMARYTYPE;
@@ -262,7 +261,7 @@ Set<String> getTypeNames() {
262261
Set<String> names = new HashSet<>();
263262
for (NodeState type : types) {
264263
names.add(type.getName(JCR_NODETYPENAME));
265-
addAll(names, type.getNames(REP_SUPERTYPES));
264+
type.getNames(REP_SUPERTYPES).forEach(names::add);
266265
}
267266
return names;
268267
}
@@ -308,7 +307,7 @@ private boolean nameSetContains(@NotNull String set, @NotNull String name) {
308307
private Set<String> getNameSet(@NotNull String set) {
309308
Set<String> names = new HashSet<>();
310309
for (NodeState type : types) {
311-
addAll(names, type.getNames(set));
310+
type.getNames(set).forEach(names::add);
312311
}
313312
return names;
314313
}

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeRegistration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.jackrabbit.oak.plugins.nodetype;
1818

19-
import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll;
2019
import static org.apache.jackrabbit.guava.common.collect.Iterables.contains;
2120
import static java.util.Collections.emptyList;
2221
import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
@@ -127,8 +126,8 @@ Set<String> getModifiedTypes(NodeState beforeTypes) {
127126
for (String name : SetUtils.union(changedTypes, removedTypes)) {
128127
types.add(name);
129128
NodeState type = beforeTypes.getChildNode(name);
130-
addAll(types, type.getNames(REP_PRIMARY_SUBTYPES));
131-
addAll(types, type.getNames(REP_MIXIN_SUBTYPES));
129+
type.getNames(REP_PRIMARY_SUBTYPES).forEach(types::add);
130+
type.getNames(REP_MIXIN_SUBTYPES).forEach(types::add);
132131
}
133132
return types;
134133
}
@@ -314,7 +313,7 @@ private void mergeSupertype(NodeBuilder type, NodeState supertype) {
314313
private void mergeNameList(
315314
NodeBuilder builder, NodeState state, String listName) {
316315
Set<String> nameList = SetUtils.toLinkedSet(getNames(builder, listName));
317-
Iterables.addAll(nameList, state.getProperty(listName).getValue(NAMES));
316+
state.getProperty(listName).getValue(NAMES).forEach(nameList::add);
318317
builder.setProperty(listName, nameList, NAMES);
319318
}
320319

oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
import org.slf4j.Logger;
6868
import org.slf4j.LoggerFactory;
6969

70-
import org.apache.jackrabbit.guava.common.collect.Iterables;
71-
7270
/**
7371
* A selector within a query.
7472
*/
@@ -739,7 +737,7 @@ private PropertyValue currentOakProperty(String oakPropertyName, Integer propert
739737
if (type == Type.STRING) {
740738
ArrayList<String> strings = new ArrayList<String>();
741739
for (PropertyValue p : list) {
742-
Iterables.addAll(strings, p.getValue(Type.STRINGS));
740+
p.getValue(Type.STRINGS).forEach(strings::add);
743741
}
744742
return PropertyValues.newString(strings);
745743
}

oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.slf4j.Logger;
4444
import org.slf4j.LoggerFactory;
4545

46-
import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll;
4746
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
4847
import static org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER;
4948

@@ -77,7 +76,7 @@ final class PermissionStoreEditor implements AccessControlConstants, PermissionC
7776
Set<String> orderedChildNames = SetUtils.toLinkedSet(node.getNames(OAK_CHILD_ORDER));
7877
long n = orderedChildNames.size();
7978
if (node.getChildNodeCount(n + 1) > n) {
80-
addAll(orderedChildNames, node.getChildNodeNames());
79+
node.getChildNodeNames().forEach(orderedChildNames::add);
8180
}
8281

8382
int index = 0;

oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.jackrabbit.oak.jcr.delegate;
1818

19-
import static org.apache.jackrabbit.guava.common.collect.Iterables.addAll;
2019
import static org.apache.jackrabbit.guava.common.collect.Iterables.contains;
2120
import static org.apache.jackrabbit.guava.common.collect.Iterators.filter;
2221
import static org.apache.jackrabbit.guava.common.collect.Iterators.transform;
@@ -172,7 +171,7 @@ public boolean isProtected() throws InvalidItemStateException {
172171
Set<String> typeNames = new HashSet<>();
173172
for (Tree type : TreeUtil.getEffectiveType(tree, typeRoot)) {
174173
typeNames.add(TreeUtil.getName(type, JCR_NODETYPENAME));
175-
addAll(typeNames, TreeUtil.getNames(type, REP_SUPERTYPES));
174+
TreeUtil.getNames(type, REP_SUPERTYPES).forEach(typeNames::add);
176175
}
177176

178177
for (Tree type : types) {
@@ -450,7 +449,7 @@ public void updateMixins(Set<String> addMixinNames, Set<String> removedOakMixinN
450449
Set<String> typeNames = new LinkedHashSet<>();
451450
for (Tree type : getNodeTypes(child, typeRoot)) {
452451
typeNames.add(TreeUtil.getName(type, JCR_NODETYPENAME));
453-
addAll(typeNames, getNames(type, REP_SUPERTYPES));
452+
getNames(type, REP_SUPERTYPES).forEach(typeNames::add);
454453
}
455454

456455
Tree oldDefinition = findMatchingChildNodeDefinition(removed, name, typeNames);

0 commit comments

Comments
 (0)