[FLINK-4132] [gelly] Fix boxed comparison in CommunityDetection algorithm

This closes #2185


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/7324b9c1
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/7324b9c1
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/7324b9c1

Branch: refs/heads/master
Commit: 7324b9c1703e4673a98c8edb3f09465d0ea9cdfe
Parents: 918e5d0
Author: Greg Hogan <c...@greghogan.com>
Authored: Wed Jun 29 10:43:41 2016 -0400
Committer: Greg Hogan <c...@greghogan.com>
Committed: Thu Jun 30 13:11:41 2016 -0400

----------------------------------------------------------------------
 .../flink/graph/library/CommunityDetection.java | 37 ++++++++++----------
 1 file changed, 18 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/7324b9c1/flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
----------------------------------------------------------------------
diff --git 
a/flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
 
b/flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
index f554680..74fdd69 100644
--- 
a/flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
+++ 
b/flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
@@ -48,9 +48,9 @@ import java.util.TreeMap;
  */
 public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, 
Graph<K, Long, Double>> {
 
-       private Integer maxIterations;
+       private int maxIterations;
 
-       private Double delta;
+       private double delta;
 
        /**
         * Creates a new Community Detection algorithm instance.
@@ -63,7 +63,7 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
         * @param maxIterations The maximum number of iterations to run.
         * @param delta The hop attenuation parameter. Its default value is 
0.5.  
         */
-       public CommunityDetection(Integer maxIterations, Double delta) {
+       public CommunityDetection(int maxIterations, double delta) {
 
                this.maxIterations = maxIterations;
                this.delta = delta;
@@ -91,7 +91,7 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
                public void sendMessages(Vertex<K, Tuple2<Long, Double>> 
vertex) throws Exception {
 
                        for(Edge<K, Double> edge : getEdges()) {
-                               sendMessageTo(edge.getTarget(), new 
Tuple2<Long, Double>(vertex.getValue().f0,
+                               sendMessageTo(edge.getTarget(), new 
Tuple2<>(vertex.getValue().f0,
                                        vertex.getValue().f1 * 
edge.getValue()));
                        }
                }
@@ -101,9 +101,9 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
        public static final class VertexLabelUpdater<K> extends GatherFunction<
                        K, Tuple2<Long, Double>, Tuple2<Long, Double>> {
 
-               private Double delta;
+               private double delta;
 
-               public VertexLabelUpdater(Double delta) {
+               public VertexLabelUpdater(double delta) {
                        this.delta = delta;
                }
 
@@ -112,17 +112,17 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
                                                                
MessageIterator<Tuple2<Long, Double>> inMessages) throws Exception {
 
                        // we would like these two maps to be ordered
-                       Map<Long, Double> receivedLabelsWithScores = new 
TreeMap<Long, Double>();
-                       Map<Long, Double> labelsWithHighestScore = new 
TreeMap<Long, Double>();
+                       Map<Long, Double> receivedLabelsWithScores = new 
TreeMap<>();
+                       Map<Long, Double> labelsWithHighestScore = new 
TreeMap<>();
 
                        for (Tuple2<Long, Double> message : inMessages) {
                                // split the message into received label and 
score
-                               Long receivedLabel = message.f0;
-                               Double receivedScore = message.f1;
+                               long receivedLabel = message.f0;
+                               double receivedScore = message.f1;
 
                                // if the label was received before
                                if 
(receivedLabelsWithScores.containsKey(receivedLabel)) {
-                                       Double newScore = receivedScore + 
receivedLabelsWithScores.get(receivedLabel);
+                                       double newScore = receivedScore + 
receivedLabelsWithScores.get(receivedLabel);
                                        
receivedLabelsWithScores.put(receivedLabel, newScore);
                                } else {
                                        // first time we see the label
@@ -131,7 +131,7 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
 
                                // store the labels with the highest scores
                                if 
(labelsWithHighestScore.containsKey(receivedLabel)) {
-                                       Double currentScore = 
labelsWithHighestScore.get(receivedLabel);
+                                       double currentScore = 
labelsWithHighestScore.get(receivedLabel);
                                        if (currentScore < receivedScore) {
                                                // record the highest score
                                                
labelsWithHighestScore.put(receivedLabel, receivedScore);
@@ -144,9 +144,9 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
 
                        if(receivedLabelsWithScores.size() > 0) {
                                // find the label with the highest score from 
the ones received
-                               Double maxScore = -Double.MAX_VALUE;
-                               Long maxScoreLabel = vertex.getValue().f0;
-                               for (Long curLabel : 
receivedLabelsWithScores.keySet()) {
+                               double maxScore = Double.MIN_VALUE;
+                               long maxScoreLabel = vertex.getValue().f0;
+                               for (long curLabel : 
receivedLabelsWithScores.keySet()) {
 
                                        if 
(receivedLabelsWithScores.get(curLabel) > maxScore) {
                                                maxScore = 
receivedLabelsWithScores.get(curLabel);
@@ -155,14 +155,14 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
                                }
 
                                // find the highest score of maxScoreLabel
-                               Double highestScore = 
labelsWithHighestScore.get(maxScoreLabel);
+                               double highestScore = 
labelsWithHighestScore.get(maxScoreLabel);
                                // re-score the new label
                                if (maxScoreLabel != vertex.getValue().f0) {
                                        highestScore -= delta / 
getSuperstepNumber();
                                }
                                // else delta = 0
                                // update own label
-                               setNewVertexValue(new Tuple2<Long, 
Double>(maxScoreLabel, highestScore));
+                               setNewVertexValue(new Tuple2<>(maxScoreLabel, 
highestScore));
                        }
                }
        }
@@ -173,8 +173,7 @@ public class CommunityDetection<K> implements 
GraphAlgorithm<K, Long, Double, Gr
                Vertex<K, Long>, Vertex<K, Tuple2<Long, Double>>> {
 
                public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> 
vertex) {
-                       return new Vertex<K, Tuple2<Long, Double>>(
-                               vertex.getId(), new Tuple2<Long, 
Double>(vertex.getValue(), 1.0));
+                       return new Vertex<>(vertex.getId(), new 
Tuple2<>(vertex.getValue(), 1.0));
                }
        }
 

Reply via email to