From 5e7398234becd4005f51579847964ce48daff0e7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 25 Nov 2016 00:46:10 +0100 Subject: [PATCH] Using ternary operation --- .../org/craftedsw/tripservicekata/trip/TripService.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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) { -- 2.1.4