Last active
July 4, 2017 09:41
-
-
Save soudmaijer/88875f23b81210c31fd66e4ce3a82f9e 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
class CollateralArrangement(val trackingNumber: Int) | |
class Facility(val collateralArrangement: List<CollateralArrangement>) | |
class CollateralArrangementTuple(val collateralArrangement: CollateralArrangement, val facility: Facility) | |
val facilities = listOf(Facility(collateralArrangement = listOf(CollateralArrangement(1), CollateralArrangement(2), CollateralArrangement(3)))) | |
// with Kotlin, results in: Map<Int, CollateralArrangementTuple> | |
val map = facilities.flatMap { facility -> facility.collateralArrangement.map { Pair(it.trackingNumber, CollateralArrangementTuple(it, facility)) } }.toMap() | |
// with Java | |
Map<Integer, CollateralArrangementTuple> map = facilities.stream().flatMap(facility -> facility.getCollateralArrangement().stream().map(ca -> new Pair<>(ca.getTrackingNumber(), new CollateralArrangementTuple(ca, facility)))).collect(Collectors.toMap(Pair::getKey, Pair::getValue)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment