Skip to content

Commit cb4ae51

Browse files
committed
Some nitty simplification of Stream usage
Co-Authored-By: IntelliJ
1 parent 806f456 commit cb4ae51

File tree

44 files changed

+75
-103
lines changed

Some content is hidden

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

44 files changed

+75
-103
lines changed

algo-params/similarity-params/src/main/java/org/neo4j/gds/similarity/knn/KnnSampler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Locale;
2525
import java.util.function.LongPredicate;
26-
import java.util.stream.Collectors;
2726

2827
public interface KnnSampler {
2928

@@ -45,7 +44,7 @@ enum SamplerType {
4544
private static final List<String> VALUES = Arrays
4645
.stream(SamplerType.values())
4746
.map(SamplerType::name)
48-
.collect(Collectors.toList());
47+
.toList();
4948

5049
public static SamplerType parse(Object input) {
5150
if (input instanceof String) {

algo/src/main/java/org/neo4j/gds/embeddings/graphsage/GraphSageModelTrainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ public ModelTrainResult train(Graph graph, HugeObjectArray<double[]> features) {
154154
layers,
155155
weights,
156156
epochLocalSeed
157-
))
158-
.collect(Collectors.toList());
157+
)).toList();
159158

160159
batchTaskSampler = () -> IntStream
161160
.range(0, parameters.batchesPerIteration(graph.nodeCount()))

algo/src/main/java/org/neo4j/gds/scaleproperties/ScaleProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public ScalePropertiesResult compute() {
8080
progressTracker.beginSubTask("Prepare scalers");
8181
var scalers = params.nodeProperties().stream()
8282
.map(this::prepareScalers)
83-
.collect(Collectors.toList());
83+
.toList();
8484
progressTracker.endSubTask("Prepare scalers");
8585

8686
var scalerStatistics = IntStream

algo/src/test/java/org/neo4j/gds/allshortestpaths/IntMinPriorityQueueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void testAddAndPop() {
125125
.keySet()
126126
.stream()
127127
.sorted()
128-
.collect(Collectors.toList());
128+
.toList();
129129

130130
for (Double weight : weightGroups) {
131131
final Set<Integer> allowedIds = byWeight.get(weight);

algo/src/test/java/org/neo4j/gds/paths/bellmanford/BellmanFordMultipleNegativeCyclesTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import org.neo4j.gds.extension.GdlGraph;
2929
import org.neo4j.gds.extension.Inject;
3030
import org.neo4j.gds.extension.TestGraph;
31-
32-
import java.util.stream.Collectors;
31+
import org.neo4j.gds.paths.PathResult;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
3534

@@ -88,14 +87,14 @@ void shouldReturnNegativeCycles() {
8887
.negativeCycles()
8988
.pathSet()
9089
.stream()
91-
.collect(Collectors.toList());
90+
.toList();
9291

93-
var negativeCyclesNodes = negativeCycles.stream().map(v -> v.nodeIds()).collect(Collectors.toList());
92+
var negativeCyclesNodes = negativeCycles.stream().map(PathResult::nodeIds).toList();
9493
assertThat(negativeCyclesNodes).containsExactlyInAnyOrder(
9594
new long[]{a[1], a[3], a[4], a[1]},
9695
new long[]{a[2], a[5], a[6], a[2]}
9796
);
98-
var negativeCyclesWeights = negativeCycles.stream().map(v -> v.costs()).collect(Collectors.toList());
97+
var negativeCyclesWeights = negativeCycles.stream().map(PathResult::costs).toList();
9998
assertThat(negativeCyclesWeights).containsExactlyInAnyOrder(
10099
new double[]{0, -1, -3, -1},
101100
new double[]{0, -100, -95, -89}

algo/src/test/java/org/neo4j/gds/similarity/nodesim/ComponentNodesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.TreeSet;
4040
import java.util.function.LongPredicate;
4141
import java.util.function.LongUnaryOperator;
42-
import java.util.stream.Collectors;
4342

4443
import static org.assertj.core.api.Assertions.assertThat;
4544
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -86,7 +85,7 @@ void shouldDetermineIndexUpperBound() {
8685
}
8786
assertThat(idxUpperBoundPerComponent.get(7)).isEqualTo(-1L);
8887
int previousUpperBound = -1;
89-
for (long key : componentPerIdxUpperBound.keySet().stream().sorted().collect(Collectors.toList())) {
88+
for (long key : componentPerIdxUpperBound.keySet().stream().sorted().toList()) {
9089
switch ((int) (key - previousUpperBound)) {
9190
case 1: assertThat(componentPerIdxUpperBound.get(key)).isEqualTo(4);break;
9291
case 2: assertThat(componentPerIdxUpperBound.get(key)).isEqualTo(5);break;

algo/src/test/java/org/neo4j/gds/similarity/nodesim/TopKMapTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.ArrayList;
2929
import java.util.Comparator;
3030
import java.util.List;
31-
import java.util.stream.Collectors;
3231
import java.util.stream.Stream;
3332

3433
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -53,7 +52,7 @@ void shouldLimitTopK() {
5352
input.add(new SimilarityResult(0, 4, 20.0));
5453
input.add(new SimilarityResult(0, 5, 25.0));
5554
input.add(new SimilarityResult(0, 6, 30.0));
56-
input.addAll(input.stream().map(SimilarityResult::reverse).collect(Collectors.toList()));
55+
input.addAll(input.stream().map(SimilarityResult::reverse).toList());
5756

5857
BitSet bitSet = new BitSet();
5958
bitSet.set(0, input.size());
@@ -62,7 +61,7 @@ void shouldLimitTopK() {
6261

6362
input.forEach(sim -> topKMap.put(sim.node1, sim.node2, sim.similarity));
6463

65-
List<SimilarityResult> actual = topKMap.stream().collect(Collectors.toList());
64+
List<SimilarityResult> actual = topKMap.stream().toList();
6665

6766
assertEquals(expected, actual);
6867
}
@@ -89,7 +88,7 @@ void shouldLimitTopK3() {
8988

9089
input.forEach(sim -> topKMap.put(sim.node1, sim.node2, sim.similarity));
9190

92-
List<SimilarityResult> actual = topKMap.stream().collect(Collectors.toList());
91+
List<SimilarityResult> actual = topKMap.stream().toList();
9392

9493
assertEquals(expected, actual);
9594
}
@@ -116,7 +115,7 @@ void shouldLimitTopK3Ascending() {
116115

117116
input.forEach(sim -> topKMap.put(sim.node1, sim.node2, sim.similarity));
118117

119-
List<SimilarityResult> actual = topKMap.stream().collect(Collectors.toList());
118+
List<SimilarityResult> actual = topKMap.stream().toList();
120119

121120
assertEquals(expected, actual);
122121
}
@@ -148,7 +147,7 @@ void shouldKeepFirstWhenValuesAreIdentical(Comparator<SimilarityResult> comparat
148147

149148
input.forEach(sim -> topKMap.put(sim.node1, sim.node2, sim.similarity));
150149

151-
List<SimilarityResult> actual = topKMap.stream().collect(Collectors.toList());
150+
List<SimilarityResult> actual = topKMap.stream().toList();
152151

153152
assertEquals(expected, actual);
154153
}

algo/src/test/java/org/neo4j/gds/traversal/RandomWalkTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import java.util.Optional;
5555
import java.util.TreeSet;
5656
import java.util.concurrent.TimeUnit;
57-
import java.util.stream.Collectors;
5857

5958
import static org.assertj.core.api.Assertions.assertThat;
6059
import static org.assertj.core.api.Assertions.assertThatNoException;
@@ -101,7 +100,7 @@ void testWithDefaultConfig() {
101100
TerminationFlag.RUNNING_TRUE
102101
);
103102

104-
List<long[]> result = randomWalk.compute().collect(Collectors.toList());
103+
List<long[]> result = randomWalk.compute().toList();
105104

106105
int expectedNumberOfWalks = walkParameters.walksPerNode() * 3;
107106
assertEquals(expectedNumberOfWalks, result.size());
@@ -133,7 +132,7 @@ void shouldBeDeterministic() {
133132
ProgressTracker.NULL_TRACKER,
134133
DefaultPool.INSTANCE,
135134
TerminationFlag.RUNNING_TRUE
136-
).compute().collect(Collectors.toList());
135+
).compute().toList();
137136

138137
var secondResult = RandomWalk.create(
139138
graph,
@@ -145,7 +144,7 @@ void shouldBeDeterministic() {
145144
ProgressTracker.NULL_TRACKER,
146145
DefaultPool.INSTANCE,
147146
TerminationFlag.RUNNING_TRUE
148-
).compute().collect(Collectors.toList());
147+
).compute().toList();
149148

150149
var firstResultAsSet = new TreeSet<long[]>(Arrays::compare);
151150
firstResultAsSet.addAll(firstResult);
@@ -174,7 +173,7 @@ void testSampleFromMultipleRelationshipTypes() {
174173
);
175174

176175
int expectedNumberOfWalks = walkParameters.walksPerNode() * 3;
177-
List<long[]> result = randomWalk.compute().collect(Collectors.toList());
176+
List<long[]> result = randomWalk.compute().toList();
178177
assertEquals(expectedNumberOfWalks, result.size());
179178
long nodeZero = graph.toMappedNodeId("a");
180179
long[] walkForNodeZero = result
@@ -381,8 +380,9 @@ void parallelWeighted() {
381380
DefaultPool.INSTANCE,
382381
TerminationFlag.RUNNING_TRUE
383382
);
383+
var actual = randomWalk.compute().toList();
384384

385-
assertThat(randomWalk.compute().collect(Collectors.toList()))
385+
assertThat(actual)
386386
.matches(walks -> walks.size() <= nodeCount * walksPerNode)
387387
.allMatch(walk -> walk.length <= walkLength);
388388
}
@@ -411,8 +411,9 @@ void testWithConfiguredOffsetStartNodes() {
411411
DefaultPool.INSTANCE,
412412
TerminationFlag.RUNNING_TRUE
413413
);
414+
var actual = randomWalk.compute().toList();
414415

415-
assertThat(randomWalk.compute().collect(Collectors.toList()))
416+
assertThat(actual)
416417
.matches(walks -> walks.size() == 2)
417418
.anyMatch(walk -> walk[0] == aInternalId)
418419
.anyMatch(walk -> walk[0] == bInternalId);

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/GraphWriteNodePropertiesConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ default Collection<NodeLabel> validNodeLabels(GraphStore graphStore) {
5656
List<String> nodePropertiesRequestedByUser = nodeProperties()
5757
.stream()
5858
.map(UserInputWriteProperties.PropertySpec::nodeProperty)
59-
.collect(Collectors.toList());
59+
.toList();
6060

6161
return nodeLabelIdentifiers(graphStore)
6262
.stream()

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/StreamRelationshipsApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
import org.neo4j.gds.api.GraphStore;
2525
import org.neo4j.gds.core.concurrency.ParallelUtil;
2626

27-
import java.util.stream.Collectors;
2827
import java.util.stream.LongStream;
2928
import java.util.stream.Stream;
3029

3130
public class StreamRelationshipsApplication {
3231
Stream<TopologyResult> compute(GraphStore graphStore, GraphStreamRelationshipsConfig configuration) {
3332
var relationshipTypesAndGraphs = configuration.relationshipTypeIdentifiers(graphStore).stream()
3433
.map(relationshipType -> Tuples.pair(relationshipType.name(), graphStore.getGraph(relationshipType)))
35-
.collect(Collectors.toList());
34+
.toList();
3635

3736
return ParallelUtil.parallelStream(
3837
LongStream.range(0, graphStore.nodeCount()),

0 commit comments

Comments
 (0)