Skip to content

Commit b4b3ba9

Browse files
committed
Use streams API internally
1 parent bd80d71 commit b4b3ba9

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/main/java/org/apache/commons/jxpath/BasicNodeSet.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Collections;
2222
import java.util.List;
23+
import java.util.stream.Collectors;
2324

2425
/**
2526
* A simple implementation of {@link NodeSet} that behaves as a collection of pointers.
@@ -65,12 +66,7 @@ private synchronized void clear() {
6566
@Override
6667
public synchronized List getNodes() {
6768
if (nodes == null) {
68-
nodes = new ArrayList<>();
69-
for (int i = 0; i < pointers.size(); i++) {
70-
final Pointer pointer = pointers.get(i);
71-
nodes.add(pointer.getNode());
72-
}
73-
nodes = Collections.unmodifiableList(nodes);
69+
nodes = Collections.unmodifiableList(pointers.stream().map(Pointer::getNode).collect(Collectors.toList()));
7470
}
7571
return nodes;
7672
}
@@ -86,12 +82,7 @@ public synchronized List<Pointer> getPointers() {
8682
@Override
8783
public synchronized List getValues() {
8884
if (values == null) {
89-
values = new ArrayList<>();
90-
for (int i = 0; i < pointers.size(); i++) {
91-
final Pointer pointer = pointers.get(i);
92-
values.add(pointer.getValue());
93-
}
94-
values = Collections.unmodifiableList(values);
85+
values = Collections.unmodifiableList(pointers.stream().map(Pointer::getValue).collect(Collectors.toList()));
9586
}
9687
return values;
9788
}

0 commit comments

Comments
 (0)