Created
February 18, 2015 15:13
-
-
Save alexcrt/9cf93fb2c83a451abc77 to your computer and use it in GitHub Desktop.
Query implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Map; | |
import static java.util.stream.Collectors.groupingBy; | |
import static java.util.stream.Collectors.summingInt; | |
public class StackStuff { | |
public static void main(String [] args) { | |
Report report = new Report(); | |
Map<String, Integer> map = report.getQueries() | |
.stream() | |
.collect(groupingBy(q -> q.getChoice(), | |
summingInt((Query q)-> q.queryOutput))); | |
System.out.println(map); //{Choice1=2, Choice2=1} | |
} | |
} | |
class Report { | |
List<Query> getQueries() { | |
return Arrays.asList(new Query("Choice1"), new Query("Choice1"), new Query("Choice2")); | |
} | |
} | |
class Query { | |
String choices; | |
int queryOutput = 1; | |
public Query(String choices) { | |
this.choices = choices; | |
} | |
public String getChoice() { | |
return this.choices; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment