/** * Returns a file pattern that is a sequence of this and the given pattern. * @param pattern the target pattern * @return the resolved pattern */ public FilePattern resolve(FilePattern pattern) { if (segments.isEmpty()) { return pattern; } List<FilePattern.Segment> results = new ArrayList<>(); FilePattern prefix = FilePattern.compile(toString()); results.addAll(prefix.getSegments()); results.addAll(pattern.getSegments()); return FilePattern.of(results); }
/** * Extracts the rest resource pattern of the given path. * @param path the target path * @return the rest resource pattern * @see #headOf(String) */ public Optional<FilePattern> restOf(String path) { if (BasePath.isEmpty(path)) { return Optional.empty(); } FilePattern pattern = FilePattern.compile(path); if (segments.isEmpty()) { return Optional.of(pattern); } BasePath other = headOf(pattern); if (this.isPrefixOf(other) == false) { throw new IllegalArgumentException(MessageFormat.format( "\"{0}\" must be a prefix of the path: {1}", this, path)); } if (segments.size() == pattern.getSegments().size()) { return Optional.empty(); } else { return Optional.of(FilePattern.of(pattern.getSegments().subList( segments.size(), pattern.getSegments().size()))); } }