Last active
August 29, 2015 14:14
-
-
Save milingo/d90d962d8ec81d095c5a to your computer and use it in GitHub Desktop.
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
# Turn a List<> into String[] | |
String[] strings = list.stream().toArray(String[]::new); | |
# Reduce by collecting over a field | |
list.stream().collect(Collectors.mapping( | |
Person::getName, | |
Collectors.toList())), | |
# Run several tasks asynchronously and wait for them | |
CompletableFuture<Map<String, List<String>>> campaignsByGeohashWithLocationsFuture = | |
CompletableFuture.supplyAsync(() -> findCampaignIdsInCoordinates(request)); | |
CompletableFuture<Map<String, List<String>>> campaignByUserWithLocationsFuture = | |
CompletableFuture.supplyAsync(() -> findCampaignsIdsForUser(request)); | |
Map<String, List<String>> campaignsByGeohashWithLocations = waitForResult(campaignsByGeohashWithLocationsFuture); | |
Map<String, List<String>> campaignByUserWithLocations = waitForResult(campaignByUserWithLocationsFuture); | |
private Map<String, List<String>> waitForResult(CompletableFuture<Map<String, List<String>>> campaignsWithLocationsFuture) { | |
Map<String, List<String>> campaignsWithLocations; | |
try { | |
campaignsWithLocations = campaignsWithLocationsFuture.get(); | |
} catch (Exception e) { | |
campaignsWithLocations = new HashMap<>(); | |
} | |
return campaignsWithLocations; | |
} |
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
_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment