Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.cuny.hunter.streamrefactoring.core.analysis;

public enum CollectorKind {
CONCURRENT,
NONCONCURRENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ public enum PreconditionSuccess {
P2,
P3,
P4,
P5

P5,
P6,
P7,
P8,
P9,
P10,
P11
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum Refactoring {
CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL,
OPTIMIZE_PARALLEL_STREAM
OPTIMIZE_PARALLEL_STREAM,
OPTIMIZE_COMPLEX_MUTABLE_REDUCTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ private static String getMethodIdentifier(IMethodBinding methodBinding) {
private final MethodDeclaration enclosingMethodDeclaration;

private final TypeDeclaration enclosingTypeDeclaration;

private CollectorKind collectorKind;

private boolean hasPossibleSideEffects;

Expand Down Expand Up @@ -634,6 +636,10 @@ public Set<Ordering> getPossibleOrderings() {
return possibleOrderings.stream().map(e -> e == null ? initialOrdering : e).collect(Collectors.toSet());
}

public CollectorKind getCollectorKind() {
return this.collectorKind;
}

public Refactoring getRefactoring() {
return this.refactoring;
}
Expand Down Expand Up @@ -824,6 +830,10 @@ protected void setInitialOrdering(Ordering initialOrdering) {
Objects.requireNonNull(initialOrdering);
this.initialOrdering = initialOrdering;
}

protected void setCollectorKind(CollectorKind collectorKind) {
this.collectorKind = collectorKind;
}

private void setPassingPrecondition(PreconditionSuccess succcess) {
if (this.passingPrecondition == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum TransformationAction {
CONVERT_TO_PARALLEL,
UNORDER,
CONVERT_TO_SEQUENTIAL

CONVERT_TO_SEQUENTIAL,
CONVERT_COLLECTOR_TO_CONCURRENT,
CONVERT_COLLECTOR_TO_NON_CONCURRENT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P6 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.stream()
.collect(Collectors.groupingByConcurrent(Widget::getColor));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P7 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.parallelStream()
.collect(Collectors.groupingBy(Widget::getColor));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P8 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, List<Widget>> widgetsByColor = orderedWidgets.parallelStream()
.collect(Collectors.groupingByConcurrent(Widget::getColor));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P9 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, Set<Widget>> widgetsByColor = orderedWidgets.stream()
.collect(Collectors.groupingBy(Widget::getColor, HashMap::new, Collectors.toSet()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P10 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, Set<Widget>> widgetsByColor = orderedWidgets.stream().collect(Collectors.groupingByConcurrent(
Widget::getColor, ConcurrentHashMap::new, Collectors.toCollection(LinkedHashSet::new)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package p;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import edu.cuny.hunter.streamrefactoring.annotations.*;
import p.A.Widget.Color;

public class A {

static class Widget {
enum Color {
RED, BLUE, GREEN, PINK, ORANGE, YELLOW
};

public Color getColor() {
return this.getColor();
}
}

/**
* P11 in table 3
*/
@EntryPoint
void m() {
Collection<Widget> orderedWidgets = new ArrayList<>();
Map<Color, Set<Widget>> widgetsByColor = orderedWidgets.parallelStream()
.collect(Collectors.groupingBy(Widget::getColor, HashMap::new, Collectors.toSet()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.jdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;

import edu.cuny.hunter.streamrefactoring.core.analysis.CollectorKind;
import edu.cuny.hunter.streamrefactoring.core.analysis.ExecutionMode;
import edu.cuny.hunter.streamrefactoring.core.analysis.Ordering;
import edu.cuny.hunter.streamrefactoring.core.analysis.PreconditionFailure;
Expand Down Expand Up @@ -287,6 +288,12 @@ private void helper(StreamAnalysisExpectedResult... expectedResults) throws Exce

Set<Ordering> orderings = stream.getPossibleOrderings();
assertEquals(errorMessage("orderings", result), result.getExpectedOrderings(), orderings);

// exceptedCollecterKind is initialized in the excepted result class
if (result.getExceptedCollectorKind() != null) {
CollectorKind collectorKind = stream.getCollectorKind();
assertEquals(errorMessage("collector kind", result), result.getExceptedCollectorKind(), collectorKind);
}

assertEquals(errorMessage("side effects", result), result.isExpectingSideEffects(),
stream.hasPossibleSideEffects());
Expand Down Expand Up @@ -704,4 +711,73 @@ public void testField() throws Exception {
false, EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P1,
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK, Collections.emptySet()));
}

/**
* Test #64. Test P6 in table3.
*/
public void testConcurrentReduction() throws Exception {
helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.ORDERED), CollectorKind.CONCURRENT, false, false, true,
EnumSet.of(TransformationAction.CONVERT_COLLECTOR_TO_NON_CONCURRENT), PreconditionSuccess.P6,
Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK, Collections.emptySet()));
}

/**
* Test #64. Test P7 in table 3.
*/
public void testConcurrentReduction1() throws Exception {
helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), CollectorKind.NONCONCURRENT, false, false, true,
EnumSet.of(TransformationAction.CONVERT_TO_SEQUENTIAL), PreconditionSuccess.P7,
Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK, Collections.emptySet()));
}

/**
* Test #64. Test P8 in table 3.
*/
public void testConcurrentReduction2() throws Exception {
HashSet<TransformationAction> transformations = new HashSet<>();
transformations.add(TransformationAction.CONVERT_COLLECTOR_TO_NON_CONCURRENT);
transformations.add(TransformationAction.CONVERT_TO_SEQUENTIAL);

helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), CollectorKind.CONCURRENT, false, false, true, transformations,
PreconditionSuccess.P8, Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK,
Collections.emptySet()));
}

/**
* Test #64. Test P9 in table 3.
*/
public void testConcurrentReduction3() throws Exception {
HashSet<TransformationAction> transformations = new HashSet<>();
transformations.add(TransformationAction.CONVERT_COLLECTOR_TO_CONCURRENT);
transformations.add(TransformationAction.CONVERT_TO_PARALLEL);

helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.ORDERED), CollectorKind.NONCONCURRENT, false, false, false, transformations,
PreconditionSuccess.P9, Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK,
Collections.emptySet()));
}

/**
* Test #64. Test P10 in table 3.
*/
public void testConcurrentReduction4() throws Exception {
helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
EnumSet.of(Ordering.ORDERED), CollectorKind.CONCURRENT, false, false, false,
EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P10,
Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK, Collections.emptySet()));
}

/**
* Test #64. Test P11 in table 3.
*/
public void testConcurrentReduction5() throws Exception {
helper(new StreamAnalysisExpectedResult("orderedWidgets.stream()", EnumSet.of(ExecutionMode.PARALLEL),
EnumSet.of(Ordering.ORDERED), CollectorKind.NONCONCURRENT, false, false, false,
EnumSet.of(TransformationAction.CONVERT_COLLECTOR_TO_CONCURRENT), PreconditionSuccess.P11,
Refactoring.OPTIMIZE_COMPLEX_MUTABLE_REDUCTION, RefactoringStatus.OK, Collections.emptySet()));
}

}
Loading