Skip to content

Commit 2c307de

Browse files
yiming-tang-cskhatchad
authored andcommitted
Add test cases for concurrent reductions (#150)
* add test cases and fail the stream * calculate LOC * Revert "calculate LOC" This reverts commit 034b677. * revert changing functional code * change test cases * change test * change test cases * change refactoring * delete useless importation * Remove extra space. * change name and collections * Add collector kind * remove duplication * improve format * remove overloading helper * format * remove duplication * Remove whitespace addition.
1 parent ece798b commit 2c307de

File tree

13 files changed

+327
-5
lines changed

13 files changed

+327
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package edu.cuny.hunter.streamrefactoring.core.analysis;
2+
3+
public enum CollectorKind {
4+
CONCURRENT,
5+
NONCONCURRENT
6+
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/PreconditionSuccess.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public enum PreconditionSuccess {
55
P2,
66
P3,
77
P4,
8-
P5
9-
8+
P5,
9+
P6,
10+
P7,
11+
P8,
12+
P9,
13+
P10,
14+
P11
1015
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Refactoring.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
*/
88
public enum Refactoring {
99
CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL,
10-
OPTIMIZE_PARALLEL_STREAM
10+
OPTIMIZE_PARALLEL_STREAM,
11+
OPTIMIZE_COMPLEX_MUTABLE_REDUCTION
1112
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Stream.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class Stream {
100100
private IR enclosingMethodDeclarationIR;
101101

102102
private final TypeDeclaration enclosingTypeDeclaration;
103+
104+
private CollectorKind collectorKind;
103105

104106
private boolean hasPossibleSideEffects;
105107

@@ -480,6 +482,10 @@ public Set<Ordering> getPossibleOrderings() {
480482
return possibleOrderings.stream().map(e -> e == null ? initialOrdering : e).collect(Collectors.toSet());
481483
}
482484

485+
public CollectorKind getCollectorKind() {
486+
return this.collectorKind;
487+
}
488+
483489
public Refactoring getRefactoring() {
484490
return this.refactoring;
485491
}
@@ -667,6 +673,10 @@ protected void setInitialOrdering(Ordering initialOrdering) {
667673
Objects.requireNonNull(initialOrdering);
668674
this.initialOrdering = initialOrdering;
669675
}
676+
677+
protected void setCollectorKind(CollectorKind collectorKind) {
678+
this.collectorKind = collectorKind;
679+
}
670680

671681
private void setPassingPrecondition(PreconditionSuccess succcess) {
672682
if (this.passingPrecondition == null)

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/TransformationAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum TransformationAction {
44
CONVERT_TO_PARALLEL,
55
UNORDER,
6-
CONVERT_TO_SEQUENTIAL
7-
6+
CONVERT_TO_SEQUENTIAL,
7+
CONVERT_COLLECTOR_TO_CONCURRENT,
8+
CONVERT_COLLECTOR_TO_NON_CONCURRENT
89
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Collectors;
8+
9+
import edu.cuny.hunter.streamrefactoring.annotations.*;
10+
import p.A.Widget.Color;
11+
12+
public class A {
13+
14+
static class Widget {
15+
enum Color {
16+
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
17+
};
18+
19+
public Color getColor() {
20+
return this.getColor();
21+
}
22+
}
23+
24+
/**
25+
* P6 in table 3
26+
*/
27+
@EntryPoint
28+
void m() {
29+
Collection<Widget> orderedWidgets = new ArrayList<>();
30+
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.stream()
31+
.collect(Collectors.groupingByConcurrent(Widget::getColor));
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Collectors;
8+
9+
import edu.cuny.hunter.streamrefactoring.annotations.*;
10+
import p.A.Widget.Color;
11+
12+
public class A {
13+
14+
static class Widget {
15+
enum Color {
16+
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
17+
};
18+
19+
public Color getColor() {
20+
return this.getColor();
21+
}
22+
}
23+
24+
/**
25+
* P7 in table 3
26+
*/
27+
@EntryPoint
28+
void m() {
29+
Collection<Widget> orderedWidgets = new ArrayList<>();
30+
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.parallelStream()
31+
.collect(Collectors.groupingBy(Widget::getColor));
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Collectors;
8+
9+
import edu.cuny.hunter.streamrefactoring.annotations.*;
10+
import p.A.Widget.Color;
11+
12+
public class A {
13+
14+
static class Widget {
15+
enum Color {
16+
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
17+
};
18+
19+
public Color getColor() {
20+
return this.getColor();
21+
}
22+
}
23+
24+
/**
25+
* P8 in table 3
26+
*/
27+
@EntryPoint
28+
void m() {
29+
Collection<Widget> orderedWidgets = new ArrayList<>();
30+
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.parallelStream()
31+
.collect(Collectors.groupingByConcurrent(Widget::getColor));
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Set;
8+
import java.util.stream.Collectors;
9+
10+
import edu.cuny.hunter.streamrefactoring.annotations.*;
11+
import p.A.Widget.Color;
12+
13+
public class A {
14+
15+
static class Widget {
16+
enum Color {
17+
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
18+
};
19+
20+
public Color getColor() {
21+
return this.getColor();
22+
}
23+
}
24+
25+
/**
26+
* P9 in table 3
27+
*/
28+
@EntryPoint
29+
void m() {
30+
Collection<Widget> orderedWidgets = new ArrayList<>();
31+
Map<Color, Set<Widget>> widgetsByColor = orderedWidgets.stream()
32+
.collect(Collectors.groupingBy(Widget::getColor, HashMap::new, Collectors.toSet()));
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.LinkedHashSet;
6+
import java.util.Map;
7+
import java.util.Set;
8+
import java.util.concurrent.ConcurrentHashMap;
9+
import java.util.stream.Collectors;
10+
11+
import edu.cuny.hunter.streamrefactoring.annotations.*;
12+
import p.A.Widget.Color;
13+
14+
public class A {
15+
16+
static class Widget {
17+
enum Color {
18+
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
19+
};
20+
21+
public Color getColor() {
22+
return this.getColor();
23+
}
24+
}
25+
26+
/**
27+
* P10 in table 3
28+
*/
29+
@EntryPoint
30+
void m() {
31+
Collection<Widget> orderedWidgets = new ArrayList<>();
32+
Map<Color, Set<Widget>> widgetsByColor = orderedWidgets.stream().collect(Collectors.groupingByConcurrent(
33+
Widget::getColor, ConcurrentHashMap::new, Collectors.toCollection(LinkedHashSet::new)));
34+
}
35+
}

0 commit comments

Comments
 (0)