Last active
December 29, 2017 17:01
-
-
Save smallufo/7c63929b0456b8568f2742a3a714f634 to your computer and use it in GitHub Desktop.
From J to K
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
// Write Once Read Never | |
Map<Double , Tuple2<Star , StationaryType>> map = stars | |
.stream() | |
.flatMap(star -> { | |
List<Tuple2<Double , StationaryType>> list = getPeriodStationary(star, fromGmt, toGmt, starPositionImpl); | |
return list.stream().map(t -> Tuple.tuple(t.v1() , star , t.v2())); | |
}).collect(Collectors.toMap(Tuple3::v1, t -> Tuple.tuple(t.v2() , t.v3()) , (v1, v2) -> v1 , TreeMap::new)); | |
return map.entrySet().stream() | |
.map(entry -> Tuple.tuple(entry.getKey() , entry.getValue().v1() , entry.getValue().v2())) | |
.collect(Collectors.toList()); |
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
// Translated by IntelliJ | |
// convert Tuple2/Tuple3 to Pair/Triple | |
// WORKING , But WTF | |
val map = stars | |
.stream() | |
.flatMap { star -> | |
val list = getPeriodStationary(star, fromGmt, toGmt, starPositionImpl) | |
list.stream().map { (first, second) -> Triple(first, star, second) } | |
}.collect<TreeMap<Double, Pair<Star, StationaryType>>, Any>(Collectors.toMap(Function<Triple<Double, Star, StationaryType>, Double> { it.getFirst() }, { (_, second, third) -> Pair(second, third) }, { v1, (first, second) -> v1 }, Supplier<TreeMap<Double, Pair<Star, StationaryType>>> { TreeMap() })) | |
return map.entries.stream() | |
.map { entry -> Triple(entry.key, entry.value.first, entry.value.second) } | |
.collect<List<Triple<Double, Star, StationaryType>>, Any>(Collectors.toList()) |
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
// Concise & Slick | |
return stars.flatMap { star -> | |
getPeriodStationary(star , fromGmt , toGmt , starPositionImpl) | |
.map { (gmt , type) -> Triple(gmt , star , type) } | |
}.sortedBy { triple -> triple.first } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment