Using ternary operation
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 23:46:10 +0000 (00:46 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 24 Nov 2016 23:46:10 +0000 (00:46 +0100)
TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java

index aaa8992..b2c1650 100644 (file)
@@ -15,16 +15,9 @@ public class TripService {
                        throw new UserNotLoggedInException();\r
                }\r
                \r
-               // Getting rid of variables in legacy code is great because if we do it,\r
-               // it will be easier for us to refactor the code.\r
-               // Once we take away as many variables as posible we can remake optimizations\r
-               // but not before.\r
-               // We managed to get a symmetrical if (ternary operation)\r
-               if (user.isFriendsWith(loggedInUser)) {\r
-                       return tripsBy(user);\r
-               } else {\r
-                       return new ArrayList<>();\r
-               }\r
+               return user.isFriendsWith(loggedInUser)\r
+                               ? tripsBy(user)\r
+                           : new ArrayList<>();\r
        }\r
 \r
        protected List<Trip> tripsBy(User user) {\r