From: Gustavo Martin Morcuende Date: Thu, 24 Nov 2016 23:46:10 +0000 (+0100) Subject: Using ternary operation X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5e7398234becd4005f51579847964ce48daff0e7;p=JavaForFun Using ternary operation --- diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java index aaa8992..b2c1650 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java @@ -15,16 +15,9 @@ public class TripService { throw new UserNotLoggedInException(); } - // Getting rid of variables in legacy code is great because if we do it, - // it will be easier for us to refactor the code. - // Once we take away as many variables as posible we can remake optimizations - // but not before. - // We managed to get a symmetrical if (ternary operation) - if (user.isFriendsWith(loggedInUser)) { - return tripsBy(user); - } else { - return new ArrayList<>(); - } + return user.isFriendsWith(loggedInUser) + ? tripsBy(user) + : new ArrayList<>(); } protected List tripsBy(User user) {