@Override public Path<?> next() { Path<?> current = path; path = current.getParent().orElse(null); return current; }
/** * Checks whether this path is a root path, i.e. it has no parent path. * @return <code>true</code> if it is a root path, <code>false</code> otherwise */ default boolean isRootPath() { return !getParent().isPresent(); }
/** * Gets the path full name, including any parent path, separated by a dot <code>.</code> character. * @param nameMapper The function to use to obtain the path name (not null) * @return Path full name */ default String fullName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent().map(pr -> stream().map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))).orElse(getName()); }
/** * Gets the <em>relative</em> path name, separated by a dot <code>.</code> character, i.e. exclude any * {@link FinalPath} path instance from path name composition. * @param nameMapper The function to use to obtain the path name (not null) * @return Path relative name, en empty String if this Path is a {@link FinalPath} itself. */ default String relativeName(Function<Path<?>, String> nameMapper) { ObjectUtils.argumentNotNull(nameMapper, "Path name mapper function must be not null"); return getParent() .map(pr -> stream().filter(p -> !FinalPath.class.isAssignableFrom(p.getClass())) .map(p -> nameMapper.apply(p)) .collect(LinkedList<String>::new, LinkedList::addFirst, (a, b) -> a.addAll(0, b)).stream() .collect(Collectors.joining("."))) .orElse(FinalPath.class.isAssignableFrom(this.getClass()) ? "" : getName()); }
/** * Create a new {@link BooleanProperty} from given <code>path</code>, using given {@link Path} <code>name</code>. * @param path Path from which to obtain the property path name (not null) * @return {@link BooleanProperty} builder */ static BooleanPropertyBuilder create(Path<Boolean> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); BooleanPropertyBuilder builder = create(path.getName()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link StringProperty} from given <code>path</code>, using given {@link Path} <code>name</code>. * @param path Path from which to obtain the property path name (not null) * @return {@link StringProperty} builder */ static StringPropertyBuilder create(Path<String> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); StringPropertyBuilder builder = create(path.getName()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a {@link PathExpression} from given {@link Path}. * @param <T> Path type * @param path Suorce path * @return A new {@link PathExpression} with the same name, type and parent of the given path */ static <T> PathExpression<T> from(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); DefaultPathExpression<T> expression = new DefaultPathExpression<>(path.getName(), path.getType()); path.getParent().ifPresent(p -> expression.parent(p)); return expression; }
/** * Create a new {@link NumericProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link NumericProperty} builder */ static <T extends Number> NumericPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); NumericPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link PathProperty} from given <code>path</code>, using given {@link Path} <code>name</code> and * <code>type</code>. * @param <T> Property (path) type * @param path Path from which to obtain the property path name and type (not null) * @return {@link PathProperty} builder */ static <T> PathPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); PathPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link TemporalProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link TemporalProperty} builder */ static <T> TemporalPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); TemporalPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }