/** * Extracts the <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</a> starting * with the supplied {@code head} resource from the supplied source {@link Model}. The statements making * up the RDF Collection will be added to the supplied statement collection, which will also be returned. * * @param sourceModel * the source model, containing the RDF Collection to be read. * @param head * the {@link Resource} that represents the list head, that is the start resource of the RDF * Collection to be read. May not be {@code null}. a {@link Collection} of {@link Statement} * objects (for example a {@link Model}) to which the RDF Collection statements will be added. May * not be {@code null}. * @param sink * a {@link Collection} of {@link Statement} objects (for example a {@link Model}) to which the RDF * Collection statements will be added. May not be {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. * @return the supplied sink {@link Collection} of {@link Statement}s, with the Statements of the RDF * Collection added. */ public static <C extends Collection<Statement>> C getCollection(Model sourceModel, Resource head, C sink, Resource... contexts) { Objects.requireNonNull(sourceModel, "input model may not be null"); extract(sourceModel, head, st -> sink.add(st), contexts); return sink; }
consumeCollection(values, head, st -> sink.add(st), contexts); return sink;
consumeValues(m, head, v -> collection.add(v), contexts);
/** * Extracts the <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</a> starting * with the supplied {@code head} resource from the supplied source {@link Model}. The statements making * up the RDF Collection will be added to the supplied statement collection, which will also be returned. * * @param sourceModel * the source model, containing the RDF Collection to be read. * @param head * the {@link Resource} that represents the list head, that is the start resource of the RDF * Collection to be read. May not be {@code null}. a {@link Collection} of {@link Statement} * objects (for example a {@link Model}) to which the RDF Collection statements will be added. May * not be {@code null}. * @param sink * a {@link Collection} of {@link Statement} objects (for example a {@link Model}) to which the RDF * Collection statements will be added. May not be {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. * @return the supplied sink {@link Collection} of {@link Statement}s, with the Statements of the RDF * Collection added. */ public static <C extends Collection<Statement>> C getCollection(Model sourceModel, Resource head, C sink, Resource... contexts) { Objects.requireNonNull(sourceModel, "input model may not be null"); extract(sourceModel, head, st -> sink.add(st), contexts); return sink; }
consumeValues(m, head, v -> collection.add(v), contexts);
consumeCollection(values, head, st -> sink.add(st), contexts); return sink;
/** * Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start * resource and send them to the supplied {@link Consumer}. * * @param conn * the {@link RepositoryConnection} to use for statement retrieval. * @param head * the start resource of the RDF Collection. May not be {@code null}. * @param collectionConsumer * a {@link Consumer} function to which all retrieved statements will be reported. May not be * {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. * @throws RepositoryException * if an error occurred while reading the collection statements, for example if a cycle is * detected in the RDF collection, or some other anomaly which makes it non-wellformed. * @see RDFCollections * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection * vocabulary</a>. */ public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException { GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c); Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException; RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts); }
/** * Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start * resource and send them to the supplied {@link Consumer}. * * @param conn * the {@link RepositoryConnection} to use for statement retrieval. * @param head * the start resource of the RDF Collection. May not be {@code null}. * @param collectionConsumer * a {@link Consumer} function to which all retrieved statements will be reported. May not be * {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. * @throws RepositoryException * if an error occurred while reading the collection statements, for example if a cycle is * detected in the RDF collection, or some other anomaly which makes it non-wellformed. * @see RDFCollections * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection * vocabulary</a>. */ public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException { GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c); Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException; RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts); }
/** * Extracts the <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</a> starting * with supplied {@code head} resource from the supplied source {@link Model} and sends the statements * that make up the collection to the supplied {@link Consumer}. * * @param sourceModel * the source model, containing the RDF Collection to be read. * @param head * the {@link Resource} that represents the list head, that is the start resource of the RDF * Collection to be read. May not be {@code null}. a {@link Collection} of {@link Statement} * objects (for example a {@link Model}) to which the RDF Collection statements will be added. May * not be {@code null}. * @param consumer * the {@link Consumer} function for the Statements of the RDF Collection. May not be {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. */ public static void extract(Model sourceModel, Resource head, Consumer<Statement> consumer, Resource... contexts) { Objects.requireNonNull(sourceModel, "source model may not be null"); GetStatementOptional statementSupplier = (s, p, o, c) -> ((Model)sourceModel).filter(s, p, o, c).stream().findAny(); extract(statementSupplier, head, consumer, Models::modelException, contexts); }
/** * Extracts the <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</a> starting * with supplied {@code head} resource from the supplied source {@link Model} and sends the statements * that make up the collection to the supplied {@link Consumer}. * * @param sourceModel * the source model, containing the RDF Collection to be read. * @param head * the {@link Resource} that represents the list head, that is the start resource of the RDF * Collection to be read. May not be {@code null}. a {@link Collection} of {@link Statement} * objects (for example a {@link Model}) to which the RDF Collection statements will be added. May * not be {@code null}. * @param consumer * the {@link Consumer} function for the Statements of the RDF Collection. May not be {@code null}. * @param contexts * the context(s) from which to read the RDF Collection. This argument is an optional vararg and * can be left out. */ public static void extract(Model sourceModel, Resource head, Consumer<Statement> consumer, Resource... contexts) { Objects.requireNonNull(sourceModel, "source model may not be null"); GetStatementOptional statementSupplier = (s, p, o, c) -> ((Model)sourceModel).filter(s, p, o, c).stream().findAny(); extract(statementSupplier, head, consumer, Models::modelException, contexts); }
Function<String, Supplier<ModelException>> exceptionSupplier = Models::modelException; extract(statementSupplier, head, st -> { if (RDF.FIRST.equals(st.getPredicate())) { consumer.accept(st.getObject());
Function<String, Supplier<ModelException>> exceptionSupplier = Models::modelException; extract(statementSupplier, head, st -> { if (RDF.FIRST.equals(st.getPredicate())) { consumer.accept(st.getObject());