This is an automated email from the ASF dual-hosted git repository.

roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new bac99af1 [MINOR][IMPROVEMENT] Filter null value when selecting remote 
storage in ApplicationManager (#156)
bac99af1 is described below

commit bac99af1673c1e20c9336d81c1382fca2f973f8b
Author: jokercurry <[email protected]>
AuthorDate: Fri Aug 12 19:06:15 2022 +0800

    [MINOR][IMPROVEMENT] Filter null value when selecting remote storage in 
ApplicationManager (#156)
    
    ### What changes were proposed in this pull request?
    Filter null value when selecting remote storage.
    
    ### Why are the changes needed?
    Better code.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    No need.
---
 .../uniffle/coordinator/ApplicationManager.java    | 24 +++++-----------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git 
a/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
 
b/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
index 9d6f0fcf..40589567 100644
--- 
a/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
+++ 
b/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
@@ -19,13 +19,16 @@ package org.apache.uniffle.coordinator;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
@@ -119,25 +122,8 @@ public class ApplicationManager {
 
     // create list for sort
     List<Map.Entry<String, AtomicInteger>> sizeList =
-        Lists.newArrayList(remoteStoragePathCounter.entrySet());
-
-    sizeList.sort((entry1, entry2) -> {
-      if (entry1 == null && entry2 == null) {
-        return 0;
-      }
-      if (entry1 == null) {
-        return -1;
-      }
-      if (entry2 == null) {
-        return 1;
-      }
-      if (entry1.getValue().get() > entry2.getValue().get()) {
-        return 1;
-      } else if (entry1.getValue().get() == entry2.getValue().get()) {
-        return 0;
-      }
-      return -1;
-    });
+        
Lists.newArrayList(remoteStoragePathCounter.entrySet()).stream().filter(Objects::nonNull)
+            .sorted(Comparator.comparingInt(entry -> 
entry.getValue().get())).collect(Collectors.toList());
 
     for (Map.Entry<String, AtomicInteger> entry : sizeList) {
       String storagePath = entry.getKey();

Reply via email to