/** * Fetches data from this HierarchicalDataProvider using given * {@code query}. Only the immediate children of * {@link HierarchicalQuery#getParent()} will be returned. * * @param query * given query to request data with * @return a stream of data objects resulting from the query * * @throws IllegalArgumentException * if the query is not of type HierarchicalQuery */ @Override public default Stream<T> fetch(Query<T, F> query) { if (query instanceof HierarchicalQuery<?, ?>) { return fetchChildren((HierarchicalQuery<T, F>) query); } throw new IllegalArgumentException( "Hierarchical data provider doesn't support non-hierarchical queries"); }
/** * Fetch all the descendants of the given parent item from the given data * provider. * * @since 8.1 * @param parent * the parent item to fetch descendants for * @param dataProvider * the data provider to fetch from * @return the stream of all descendant items */ private Stream<T> fetchAllDescendants(T parent, HierarchicalDataProvider<T, ?> dataProvider) { List<T> children = dataProvider .fetchChildren(new HierarchicalQuery<>(null, parent)) .collect(Collectors.toList()); if (children.isEmpty()) { return Stream.empty(); } return children.stream() .flatMap(child -> Stream.concat(Stream.of(child), fetchAllDescendants(child, dataProvider))); }
/** * Generic method for finding direct children of a given parent, limited by * given range. * * @param parent * the parent * @param range * the range of direct children to return * @return the requested children of the given parent */ @SuppressWarnings({ "rawtypes", "unchecked" }) private Stream<T> doFetchDirectChildren(T parent, Range range) { return getDataProvider().fetchChildren(new HierarchicalQuery( range.getStart(), range.length(), getBackEndSorting(), getInMemorySorting(), getFilter(), parent)); }
getDataProvider().fetchChildren( new HierarchicalQuery<>(null, item)), depth - 1);
if (communicator.hasChildren(item)) { collapseRecursively( getDataProvider().fetchChildren( new HierarchicalQuery<>(null, item)), depth - 1);
public Collection<T> getChildren(T item) { return getDataProvider() .fetchChildren(new HierarchicalQuery<>(null, item)) .collect(Collectors.toList()); }