@Test public void getClosestRoute() { String[] urls = new String[]{ "navigation/view1", "navigation/view2", "navigation/view2/subview", "navigation/view3", "navigation/view4", "navigation/view5", "navigation/view6", "navigation/view7", "navigation/view8", "navigation/view9", "navigation" }; String currentRoutePart = "navigation/view2/subview"; RouteSimilarity res = UpNavigationHelper.getClosestRoute(currentRoutePart, urls).get(); String ress = res.getRouteString(); Assert.assertEquals(res.getRouteString(), "navigation/view2"); }
public static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes) { if (url.lastIndexOf("/") > 0) { Optional<RouteSimilarity> result = Arrays.stream(availableRoutes) .filter(routeData -> !routeData.equals(url)) .map(routeData -> new RouteSimilarity(routeData, url)) .max(Comparator.comparingInt(RouteSimilarity::getSimilarity)); if (result.isPresent()) { return result; } } return Optional.empty(); }
UpNavigationHelper implements Serializable { public static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes) { if (url.lastIndexOf("/") > 0) { Optional<RouteSimilarity> result = Arrays.stream(availableRoutes) .filter(routeData -> !routeData.equals(url)) .map(routeData -> new RouteSimilarity(routeData, url)) .max(Comparator.comparingInt(RouteSimilarity::getSimilarity)); if (result.isPresent()) { return result; } } return Optional.empty(); } }
UpNavigationHelper implements Serializable { public static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes) { if (url.lastIndexOf("/") > 0) { Optional<RouteSimilarity> result = Arrays.stream(availableRoutes) .filter(routeData -> !routeData.equals(url)) .map(routeData -> new RouteSimilarity(routeData, url)) .max(Comparator.comparingInt(RouteSimilarity::getSimilarity)); if (result.isPresent()) { return result; } } return Optional.empty(); } private  UpNavigationHelper(); }
UpNavigationHelper implements Serializable { public static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes) { if (url.lastIndexOf("/") > 0) { Optional<RouteSimilarity> result = Arrays.stream(availableRoutes) .filter(routeData -> !routeData.equals(url)) .map(routeData -> new RouteSimilarity(routeData, url)) .max(Comparator.comparingInt(RouteSimilarity::getSimilarity)); if (result.isPresent()) { return result; } } return Optional.empty(); } private  UpNavigationHelper(); static boolean routeHasUpNavigation(Class<? extends Component> navigationTarget); static UpNavigationHelper getUpNavigationHelper(); static void setUpNavigationHelper(); static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes); static void performUpNavigation(Class<? extends Component> currentNavigation); static Optional<RouteData> getClosestRoute(String url); static boolean shouldHighlight(Class<? extends Component> className, Location location); static void registerNavigationRoute(Class<? extends Component> className); void register(Class<? extends Component> className); }
UpNavigationHelper implements Serializable { public static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes) { if (url.lastIndexOf("/") > 0) { Optional<RouteSimilarity> result = Arrays.stream(availableRoutes) .filter(routeData -> !routeData.equals(url)) .map(routeData -> new RouteSimilarity(routeData, url)) .max(Comparator.comparingInt(RouteSimilarity::getSimilarity)); if (result.isPresent()) { return result; } } return Optional.empty(); } private  UpNavigationHelper(); static boolean routeHasUpNavigation(Class<? extends Component> navigationTarget); static UpNavigationHelper getUpNavigationHelper(); static void setUpNavigationHelper(); static Optional<RouteSimilarity> getClosestRoute(String url, String[] availableRoutes); static void performUpNavigation(Class<? extends Component> currentNavigation); static Optional<RouteData> getClosestRoute(String url); static boolean shouldHighlight(Class<? extends Component> className, Location location); static void registerNavigationRoute(Class<? extends Component> className); void register(Class<? extends Component> className);  }