public PathSegments apply(PathSegments input) { if (input == null || input.isEmpty()) { return input; } String last = input.last(); if (last == null || last.length() == 0) { return input; } last = new StringBuilder(last).append('.').append(extension).toString(); return PathSegments.of(false, Iterables.concat(input.consumeLast(), ImmutableList.of(last))); }
/** * Returns the device represented by a last segment extension. * @param path Path to check. * @return The resolved device or {@code null} if no device is found. */ public final Device findDeviceByLastSegmentExtension(PathSegments path) { if (path == null || path.isEmpty()) { return null; } return findDeviceByLastSegmentExtension(path.last()); }
/** * Returns the device represented by a last segment. * @param path Path to check. * @return The resolved device or {@code null} if no device is found. */ public final Device findDeviceByLastSegment(PathSegments path) { if (path == null || path.isEmpty()) { return null; } return findDeviceByLastSegment(path.last()); }
/** * Removes the extension from the last segment. * @return The modified segments. */ public PathSegments removeExtension() { if (isEmpty()) { return this; } final String last = last(); final String removed = removeExtension(last); if (last.equals(removed)) { return this; } return new PathSegments(ImmutableList.copyOf(Iterables.concat(segments.subList(0, segments.size() - 1), ImmutableList.of(removed)))); }