Created
December 20, 2018 20:52
-
-
Save carstenhag/1a538510762c4cfa4d5b9c3a10a2aa42 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
package org.dhbw.ai.fp.album; | |
import org.dhbw.ai.fp.album.model.Album; | |
import org.dhbw.ai.fp.album.model.Track; | |
import org.dhbw.ai.fp.album.persistence.CsvFileDataLoader; | |
import org.dhbw.ai.fp.optional.WithOptional; | |
import java.time.temporal.TemporalField; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Optional; | |
import java.util.function.IntPredicate; | |
import java.util.function.Predicate; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
/** | |
* Album Main Application. | |
* | |
*/ | |
public class AlbumApp | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
final var albums = CsvFileDataLoader.loadData(); | |
System.out.println("Found [" + albums.size() + "] Albums."); | |
//albums.stream().map(album -> "\t" + album).sorted().forEach(System.out::println); | |
// Gather the pairs for the numbers between 1 and 10 and their square. | |
IntStream | |
.range(0, 100) | |
.boxed() | |
.map(v -> Integer.valueOf(v) + " " + Math.pow(v, 2)) | |
.forEach(System.out::println); | |
IntPredicate predicate = x -> x % 2 == 0; | |
int lel = IntStream.range(0, 100).filter(predicate).reduce(0, (left, right) -> left + right); | |
System.out.println(lel); | |
int totalTracks = albums.stream() | |
.map(album -> album.getTracks().size()) | |
.reduce(0, (left, right) -> left + right); | |
System.out.println(totalTracks); | |
System.out.println("Distinct Artists:\n"); | |
albums.stream() | |
.flatMap(album -> album.getTracks().stream()) | |
.flatMap(track -> track.getArtist().stream()) | |
.distinct() | |
.forEach(System.out::println); | |
Map<Integer, List<Album>> map = albums.stream() | |
.collect(Collectors.groupingBy(album -> album.getReleaseDate().getYear() / 10 * 10)); | |
System.out.println(map); | |
Map<String, List<Album>> map3 = albums.stream() | |
.collect(Collectors.groupingBy(o -> { | |
if (o.getTracks().size() <= 10) { | |
return "Short"; | |
} else { | |
return "Long"; | |
} | |
})); | |
System.out.println(map3); | |
Map<Boolean, List<Album>> partition0 = albums.stream() | |
.collect(Collectors.partitioningBy(album -> album.getReleaseDate().getYear() <= 2000)); | |
System.out.println(partition0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment