[NEMO-429] SWPP TEAM2 Code Smell Fix (#277)
JIRA: [NEMO-429: SWPP TEAM2 Code Smell Fix](https://issues.apache.org/jira/projects/NEMO/issues/NEMO-429)
**Major changes:**
- exception elimination
**Minor changes to note:**
- replace lambda with method reference
- swap arguments
diff --git a/common/src/main/java/org/apache/nemo/common/ir/IRDAGChecker.java b/common/src/main/java/org/apache/nemo/common/ir/IRDAGChecker.java
index 4484505..bdca93c 100644
--- a/common/src/main/java/org/apache/nemo/common/ir/IRDAGChecker.java
+++ b/common/src/main/java/org/apache/nemo/common/ir/IRDAGChecker.java
@@ -230,7 +230,7 @@
final Optional<Integer> parallelism = v.getPropertyValue(ParallelismProperty.class);
for (final IREdge inEdge : inEdges) {
final Optional<Integer> keyRangeListSize = inEdge.getPropertyValue(PartitionSetProperty.class)
- .map(keyRangeList -> keyRangeList.size());
+ .map(List::size);
if (parallelism.isPresent() && keyRangeListSize.isPresent() && !parallelism.equals(keyRangeListSize)) {
return failure("PartitionSet must contain all task offsets required for the dst parallelism",
v, ParallelismProperty.class, inEdge, PartitionSetProperty.class);
@@ -384,7 +384,7 @@
for (final IRVertex v : irdag.getVertices()) {
final MutableObject violatingReachableVertex = new MutableObject();
- v.getPropertyValue(ScheduleGroupProperty.class).ifPresent(startingScheduleGroup -> {
+ v.getPropertyValue(ScheduleGroupProperty.class).ifPresent(startingScheduleGroup ->
irdag.dfsDo(
v,
visited -> {
@@ -394,8 +394,7 @@
}
},
DAGInterface.TraversalOrder.PreOrder,
- new HashSet<>());
- });
+ new HashSet<>()));
if (violatingReachableVertex.getValue() != null) {
return failure(
"A reachable vertex with a smaller schedule group ",
@@ -547,8 +546,7 @@
final Class... eps) {
final List<Optional> epsList = Arrays.stream(eps)
.map(ep -> (Class<VertexExecutionProperty<Serializable>>) ep)
- .map(ep -> v.getPropertyValue(ep))
- .collect(Collectors.toList());
+ .map(v::getPropertyValue).collect(Collectors.toList());
return failure(String.format("%s - [IRVertex %s: %s]", description, v.getId(), epsList.toString()));
}
@@ -557,7 +555,7 @@
final Class... eps) {
final List<Optional> epsList = Arrays.stream(eps)
.map(ep -> (Class<EdgeExecutionProperty<Serializable>>) ep)
- .map(ep -> e.getPropertyValue(ep)).collect(Collectors.toList());
+ .map(e::getPropertyValue).collect(Collectors.toList());
return failure(String.format("%s - [IREdge(%s->%s) %s: %s]",
description, e.getSrc().getId(), e.getDst().getId(), e.getId(), epsList.toString()));
}
diff --git a/common/src/test/java/org/apache/nemo/common/DAGTest.java b/common/src/test/java/org/apache/nemo/common/DAGTest.java
index 139edd9..c01fa03 100644
--- a/common/src/test/java/org/apache/nemo/common/DAGTest.java
+++ b/common/src/test/java/org/apache/nemo/common/DAGTest.java
@@ -69,6 +69,7 @@
assertEquals(1, dag.getOutgoingEdgesOf(new IntegerVertex(4)).size());
assertEquals(5, dag.getTopologicalSort().size());
+
final List<IntegerVertex> topologicalOrder = dag.getTopologicalSort();
assertEquals(1, topologicalOrder.get(0).getValue());
diff --git a/compiler/optimizer/src/main/java/org/apache/nemo/compiler/optimizer/policy/PolicyImpl.java b/compiler/optimizer/src/main/java/org/apache/nemo/compiler/optimizer/policy/PolicyImpl.java
index 9059891..2c19d4d 100644
--- a/compiler/optimizer/src/main/java/org/apache/nemo/compiler/optimizer/policy/PolicyImpl.java
+++ b/compiler/optimizer/src/main/java/org/apache/nemo/compiler/optimizer/policy/PolicyImpl.java
@@ -81,11 +81,10 @@
// Apply the pass to the DAG.
processedDAG = passToApply.apply(dag);
- final boolean advanced = processedDAG.advanceDAGSnapshot((beforePass, afterPass) -> {
+ final boolean advanced = processedDAG.advanceDAGSnapshot((beforePass, afterPass) ->
// Ensure AnnotatingPass and ReshapingPass functions as intended.
- return !((passToApply instanceof AnnotatingPass && !checkAnnotatingPass(beforePass, afterPass))
- || (passToApply instanceof ReshapingPass && !checkReshapingPass(beforePass, afterPass)));
- });
+ !((passToApply instanceof AnnotatingPass && !checkAnnotatingPass(beforePass, afterPass))
+ || (passToApply instanceof ReshapingPass && !checkReshapingPass(beforePass, afterPass))));
if (!advanced) {
throw new CompileTimeOptimizationException(passToApply.getClass().getSimpleName()
diff --git a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/DataFetcher.java b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/DataFetcher.java
index 12121c9..7af0885 100644
--- a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/DataFetcher.java
+++ b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/DataFetcher.java
@@ -22,7 +22,6 @@
import org.apache.nemo.common.ir.vertex.IRVertex;
import java.io.IOException;
-import java.util.NoSuchElementException;
/**
* An abstraction for fetching data from task-external sources.
@@ -48,7 +47,7 @@
* @throws IOException upon I/O error
* @throws java.util.NoSuchElementException if no more element is available
*/
- abstract Object fetchDataElement() throws IOException, NoSuchElementException;
+ abstract Object fetchDataElement() throws IOException;
OutputCollector getOutputCollector() {
return outputCollector;
diff --git a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/MultiThreadParentTaskDataFetcher.java b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/MultiThreadParentTaskDataFetcher.java
index 4e460f9..12cc9a6 100644
--- a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/MultiThreadParentTaskDataFetcher.java
+++ b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/task/MultiThreadParentTaskDataFetcher.java
@@ -78,7 +78,7 @@
}
@Override
- Object fetchDataElement() throws IOException, NoSuchElementException {
+ Object fetchDataElement() throws IOException {
if (firstFetch) {
fetchDataLazily();
firstFetch = false;