Skip to content

Commit

Permalink
refactor(Updated methods to use Optional):
Browse files Browse the repository at this point in the history
  • Loading branch information
br648 committed Nov 5, 2024
1 parent c0d0672 commit b6a8536
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.opentripplanner.middleware.triptracker.instruction.TripInstruction.NO_INSTRUCTION;
Expand Down Expand Up @@ -150,9 +151,16 @@ private static TripInstruction getDeviatedInstruction(TravelerPosition travelerP
return null;
}

/**
* Get the bus stop name from the 'from' place name if available.
*/
@Nullable
private static String getBusStopName(Leg busLeg) {
return (busLeg.from != null && busLeg.from.name != null) ? busLeg.from.name : null;
return Optional
.ofNullable(busLeg)
.map(leg -> leg.from)
.map(place -> place.name)
.orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ public static String getRouteShortNameFromLeg(Leg leg) {
* Get the first leg in an itinerary.
*/
public static Leg getFirstLeg(Itinerary itinerary) {
if (itinerary != null && itinerary.legs != null && !itinerary.legs.isEmpty()) {
return itinerary.legs.get(0);
}
return null;
return Optional
.ofNullable(itinerary)
.map(itin -> itin.legs)
.map(legs -> legs.get(0))
.orElse(null);
}

}

0 comments on commit b6a8536

Please sign in to comment.