Created
July 17, 2015 09:35
-
-
Save renanreismartins/df3a375305b3f0c9db9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public static void main(String[] args) { | |
| Optional<String> mapped = getMerchantOrderIdFromUrl("haveId").map(orderId -> { | |
| return orderId + " mapped"; | |
| }); | |
| System.out.println(mapped); | |
| Optional<Optional<String>> merchant = getMerchantOrderIdFromUrl("haveId").map(orderId -> { | |
| return getMerchant(orderId); | |
| }); | |
| Optional<String> merchantf = getMerchantOrderIdFromUrl("haveId").flatMap(orderId -> { | |
| return getMerchant(orderId); | |
| }); | |
| } | |
| static Optional<String> getMerchantOrderIdFromUrl(String requestUri) { | |
| if(requestUri.equals("haveId")) { | |
| return Optional.of("1"); | |
| } | |
| return Optional.empty(); | |
| } | |
| static Optional<String> getMerchant(String id) { | |
| if (id.equals("1")) { | |
| return Optional.of("Merchant"); | |
| } | |
| return Optional.empty(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment