package org.sonar.plugins.stash.issue.collector;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.ProjectIssues;
import org.sonar.plugins.stash.IssuePathResolver;

public final class SonarQubeCollector {

  private static final Logger LOGGER = LoggerFactory.getLogger(SonarQubeCollector.class);
  
  private SonarQubeCollector() {
    // NOTHING TO DO
    // Pure static class
  }

  /**
   * Create issue report according to issue list generated during SonarQube
   * analysis.
   */
  public static List<Issue> extractIssueReport(ProjectIssues projectIssues, IssuePathResolver issuePathResolver) {
    List<Issue> result = new ArrayList<>();

    for (Issue issue : projectIssues.issues()) {
      if (!issue.isNew()){
        LOGGER.debug("Issue {} is not a new issue and so, not added to the report", issue.key());
        continue;
      }

      String path = issuePathResolver.getIssuePath(issue);
      if (path == null) {
        LOGGER.debug("Issue {} is not linked to a file, not added to the report", issue.key());
        continue;
      }

      result.add(issue);
    }

    return result;
  }
}

@@ -49,30 +49,8 @@
 %0D%0A%0D%0A
-import java.io.File;%0D%0A
 impo
@@ -97,16 +97,93 @@
 l.List;%0D
+%0Aimport java.util.stream.Collectors;%0D%0Aimport java.util.stream.StreamSupport;%0D
 %0A%0D%0Aimpor
@@ -501,18 +501,16 @@
 lass);%0D%0A
-  
 %0D%0A  priv
@@ -539,60 +539,8 @@
 () %7B
-%0D%0A    // NOTHING TO DO%0D%0A    // Pure static class%0D%0A  
 %7D%0D%0A%0D
@@ -771,103 +771,357 @@
     
-List%3CIssue%3E result = new Array
+return StreamSupport.stream(%0D%0A                         projectIssues.issues().spliterator(), false)%0D%0A                        .filter(issue -%3E shouldIncludeIssue(issue, issuePathResolver))%0D%0A                        .collect(Collectors.to
 List
-%3C%3E
 (
+)
 );%0D%0A
-%0D%0A    for (Issue issue : projectIssues.issues()
+  %7D%0D%0A%0D%0A  private static boolean shouldIncludeIssue(Issue issue, IssuePathResolver issuePathResolver
 ) %7B%0D%0A
-  
     
@@ -1142,18 +1142,16 @@
 ew())%7B%0D%0A
-  
       LO
@@ -1241,39 +1241,39 @@
 ());%0D%0A      
-  continu
+return fals
 e;%0D%0A
-  
     %7D%0D%0A%0D%0A   
@@ -1273,18 +1273,16 @@
 %0D%0A%0D%0A    
-  
 String p
@@ -1331,18 +1331,16 @@
 );%0D%0A    
-  
 if (path
@@ -1352,18 +1352,16 @@
 ull) %7B%0D%0A
-  
       LO
@@ -1457,55 +1457,20 @@
     
-  continue;%0D%0A      %7D%0D%0A%0D%0A      result.add(issue)
+return false
 ;%0D%0A 
@@ -1471,26 +1471,24 @@
 se;%0D%0A    %7D%0D%0A
-%0D%0A
     return r
@@ -1490,14 +1490,12 @@
 urn 
-result
+true
 ;%0D%0A 

refactor complex method