/** * Utility method that given a {@link Location} creates a new one but ignoring the last part of it. */ public static Location deleteLastPartFromLocation(Location location) { Location.Builder builder = Location.builder(); List<String> parts = location.getParts(); builder = builder.globalName(location.getGlobalName()); for (int i = 0; i < parts.size() - 1; i++) { builder = builder.addPart(parts.get(i)); } return builder.build(); }