Class TupleQueryResultConverter


  • public class TupleQueryResultConverter
    extends Object
    Since:
    4.0.0
    Author:
    Florian Kleedorfer
    • Constructor Detail

      • TupleQueryResultConverter

        public TupleQueryResultConverter​(org.eclipse.rdf4j.query.TupleQueryResult result)
    • Method Detail

      • consumeResult

        public void consumeResult​(Consumer<org.eclipse.rdf4j.query.TupleQueryResult> consumer)
        Passes the TupleQueryResult to the consumer and closes the result afterwards.
      • applyToResult

        public <T> T applyToResult​(Function<org.eclipse.rdf4j.query.TupleQueryResult,​T> function)
        Applies the function to the TupleQueryResult and closes the result afterwards.
      • toStream

        public Stream<org.eclipse.rdf4j.query.BindingSet> toStream()
        Obtains a stream of BindingSets. The result is completely consumed and closed when the stream is returned.
      • toStream

        public <T> Stream<T> toStream​(BindingSetMapper<T> mapper)
        Obtains a Stream of mapped query results. The result is completely consumed and closed when the stream is returned. Any null values are filterd from the resulting stream.
      • toStream

        public <T,​O> Stream<O> toStream​(BindingSetMapper<T> mapper,
                                              MappingPostProcessor<T,​O> postProcessor)
        Obtains a Stream of mapped query results, using the postprocessor to map it again. Any null values are filtered from the resulting stream.
      • toSingletonMaybeOfWholeResult

        public <T> T toSingletonMaybeOfWholeResult​(TupleQueryResultMapper<T> mapper)
        Maps the whole TupleQueryResult to one object, which may be null.
      • toSingletonMaybe

        public <T> T toSingletonMaybe​(BindingSetMapper<T> mapper)
        Maps the first BindingSet in the result if one exists, throwing an exception if there are more. Returns null if there are no results or if there is one result that is mapped to null by the specified mapper.
        Throws:
        IncorrectResultSetSizeException
      • toSingletonOptional

        public <T> Optional<T> toSingletonOptional​(BindingSetMapper<T> mapper)
        Maps the first BindingSet in the result, throwing an exception if there are more than one. Returns an Optional, which is empty if there are no results or if there is one result that is mapped to null by the specified mapper.
      • mapAndCollect

        public <T,​A,​R> R mapAndCollect​(Function<org.eclipse.rdf4j.query.BindingSet,​T> mapper,
                                                   Collector<T,​A,​R> collector)
      • toMap

        public <K,​V> Map<K,​V> toMap​(Function<org.eclipse.rdf4j.query.BindingSet,​K> keyMapper,
                                                Function<org.eclipse.rdf4j.query.BindingSet,​V> valueMapper)
        Maps the query result to a Map, throwing an Exception if there are multiple values for one key.
      • toMapOfSet

        public <K,​V> Map<K,​Set<V>> toMapOfSet​(Function<org.eclipse.rdf4j.query.BindingSet,​K> keyMapper,
                                                          Function<org.eclipse.rdf4j.query.BindingSet,​V> valueMapper)
        Maps the query result to a Map of Sets.
      • toMapOfList

        public <K,​V> Map<K,​List<V>> toMapOfList​(Function<org.eclipse.rdf4j.query.BindingSet,​K> keyMapper,
                                                            Function<org.eclipse.rdf4j.query.BindingSet,​V> valueMapper)
        Maps the query result to a Map of Lists.
      • toMap

        public <T,​K,​V> Map<K,​V> toMap​(BindingSetMapper<T> mapper,
                                                        Function<T,​K> keyMapper,
                                                        Function<T,​V> valueMapper)
        Maps the query result to a Map, throwing an Exception if there are multiple values for one key.
      • toMap

        public <K,​V> Map<K,​V> toMap​(Function<org.eclipse.rdf4j.query.BindingSet,​Map.Entry<K,​V>> entryMapper)
        Maps the query result to a Map, throwing an Exception if there are multiple values for one key.
      • getBindingStream

        public Stream<org.eclipse.rdf4j.query.BindingSet> getBindingStream​(org.eclipse.rdf4j.query.TupleQueryResult result)
        If the result has only one empty binding set, this method returns an empty stream, otherwise the stream of BindingSets