Package org.eclipse.rdf4j.spring.dao.support.operation

## Class TupleQueryResultConverter

- java.lang.Object
- - org.eclipse.rdf4j.spring.dao.support.operation.TupleQueryResultConverter

-     public class TupleQueryResultConverter
      extends Object

  Since:
    4.0.0
  Author:
    Florian Kleedorfer

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `TupleQueryResultConverter​(TupleQueryResult result)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `<T> T` | `applyToResult​(Function<TupleQueryResult,​T> function)` | Applies the function to the `TupleQueryResult` and closes the result afterwards.
    `void` | `consumeResult​(Consumer<TupleQueryResult> consumer)` | Passes the `TupleQueryResult` to the consumer and closes the result afterwards.
    `Stream<BindingSet>` | `getBindingStream​(TupleQueryResult result)` | If the result has only one empty binding set, this method returns an empty stream, otherwise the stream of BindingSets
    `<T,​A,​R> R` | `mapAndCollect​(Function<BindingSet,​T> mapper, Collector<T,​A,​R> collector)` |
    `<T> List<T>` | `toList​(BindingSetMapper<T> mapper)` | Maps the query result to a `List`.
    `<T,​O> List<O>` | `toList​(BindingSetMapper<T> mapper, MappingPostProcessor<T,​O> postProcessor)` | Maps the query result to a `List`.
    `<K,​V> Map<K,​V>` | `toMap​(Function<BindingSet,​Map.Entry<K,​V>> entryMapper)` | Maps the query result to a `Map`, throwing an Exception if there are multiple values for one key.
    `<K,​V> Map<K,​V>` | `toMap​(Function<BindingSet,​K> keyMapper, Function<BindingSet,​V> valueMapper)` | Maps the query result to a `Map`, throwing an Exception if there are multiple values for one key.
    `<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.
    `<K,​V> Map<K,​List<V>>` | `toMapOfList​(Function<BindingSet,​K> keyMapper, Function<BindingSet,​V> valueMapper)` | Maps the query result to a `Map` of `List`s.
    `<T,​K,​V> Map<K,​List<V>>` | `toMapOfList​(BindingSetMapper<T> mapper, Function<T,​K> keyMapper, Function<T,​V> valueMapper)` | Maps the query result to a `Map` of `List`s.
    `<K,​V> Map<K,​Set<V>>` | `toMapOfSet​(Function<BindingSet,​K> keyMapper, Function<BindingSet,​V> valueMapper)` | Maps the query result to a `Map` of `Set`s.
    `<T,​K,​V> Map<K,​Set<V>>` | `toMapOfSet​(BindingSetMapper<T> mapper, Function<T,​K> keyMapper, Function<T,​V> valueMapper)` | Maps the query result to a `Map` of `Set`s.
    `<T> Set<T>` | `toSet​(BindingSetMapper<T> mapper)` | Maps the query result to a `Set`.
    `<T,​O> Set<O>` | `toSet​(BindingSetMapper<T> mapper, MappingPostProcessor<T,​O> postProcessor)` | Maps the query result to a `Set`.
    `<T> T` | `toSingleton​(BindingSetMapper<T> mapper)` | Maps the first `BindingSet` in the result, throwing an exception if there are no results or more than one.
    `<T,​O> O` | `toSingleton​(BindingSetMapper<T> mapper, MappingPostProcessor<T,​O> postProcessor)` | Maps the first `BindingSet` in the result, throwing an exception if there are no results or more than one.
    `<T> T` | `toSingletonMaybe​(BindingSetMapper<T> mapper)` | Maps the first `BindingSet` in the result if one exists, throwing an exception if there are more.
    `<T,​O> O` | `toSingletonMaybe​(BindingSetMapper<T> mapper, MappingPostProcessor<T,​O> postProcessor)` | Maps the first `BindingSet` in the result if one exists, throwing an exception if there are more.
    `<T> T` | `toSingletonMaybeOfWholeResult​(TupleQueryResultMapper<T> mapper)` | Maps the whole `TupleQueryResult` to one object, which may be null.
    `<T> T` | `toSingletonOfWholeResult​(TupleQueryResultMapper<T> mapper)` | Maps the whole `TupleQueryResult` to an object, throwing an exception if the mapper returns `null`.
    `<T> Optional<T>` | `toSingletonOptional​(BindingSetMapper<T> mapper)` | Maps the first `BindingSet` in the result, throwing an exception if there are more than one.
    `<T,​O> Optional<O>` | `toSingletonOptional​(BindingSetMapper<T> mapper, MappingPostProcessor<T,​O> postProcessor)` |
    `<T> Optional<T>` | `toSingletonOptionalOfWholeResult​(TupleQueryResultMapper<T> mapper)` | Maps the whole `TupleQueryResult` to one `Optional`.
    `Stream<BindingSet>` | `toStream()` | Obtains a stream of `BindingSet`s.
    `<T> Stream<T>` | `toStream​(BindingSetMapper<T> mapper)` | Obtains a `Stream` of mapped query results.
    `<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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TupleQueryResultConverter

          public TupleQueryResultConverter​(TupleQueryResult result)

  - ### Method Detail

    - #### consumeResult

          public void consumeResult​(Consumer<TupleQueryResult> consumer)

      Passes the `TupleQueryResult` to the consumer and closes the result afterwards.

    - #### applyToResult

          public <T> T applyToResult​(Function<TupleQueryResult,​T> function)

      Applies the function to the `TupleQueryResult` and closes the result afterwards.

    - #### toStream

          public Stream<BindingSet> toStream()

      Obtains a stream of `BindingSet`s. 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.

    - #### toSingletonOptionalOfWholeResult

          public <T> Optional<T> toSingletonOptionalOfWholeResult​(TupleQueryResultMapper<T> mapper)

      Maps the whole `TupleQueryResult` to one `Optional`.

    - #### toSingletonOfWholeResult

          public <T> T toSingletonOfWholeResult​(TupleQueryResultMapper<T> mapper)

      Maps the whole `TupleQueryResult` to an object, throwing an exception if the mapper returns `null`.
      Throws:
        `IncorrectResultSetSizeException`

    - #### 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.

    - #### toSingleton

          public <T> T toSingleton​(BindingSetMapper<T> mapper)

      Maps the first `BindingSet` in the result, throwing an exception if there are no results or more than one.
      Throws:
        `IncorrectResultSetSizeException`

    - #### toSingletonMaybe

          public <T,​O> O toSingletonMaybe​(BindingSetMapper<T> mapper,
                                                MappingPostProcessor<T,​O> postProcessor)

      Maps the first `BindingSet` in the result if one exists, throwing an exception if there are more.
      Throws:
        `IncorrectResultSetSizeException`

    - #### toSingletonOptional

          public <T,​O> Optional<O> toSingletonOptional​(BindingSetMapper<T> mapper,
                                                             MappingPostProcessor<T,​O> postProcessor)

    - #### toSingleton

          public <T,​O> O toSingleton​(BindingSetMapper<T> mapper,
                                           MappingPostProcessor<T,​O> postProcessor)

      Maps the first `BindingSet` in the result, throwing an exception if there are no results or more than one.
      Throws:
        `IncorrectResultSetSizeException`

    - #### mapAndCollect

          public <T,​A,​R> R mapAndCollect​(Function<BindingSet,​T> mapper,
                                                     Collector<T,​A,​R> collector)

    - #### toList

          public <T> List<T> toList​(BindingSetMapper<T> mapper)

      Maps the query result to a `List`.

    - #### toList

          public <T,​O> List<O> toList​(BindingSetMapper<T> mapper,
                                            MappingPostProcessor<T,​O> postProcessor)

      Maps the query result to a `List`.

    - #### toSet

          public <T> Set<T> toSet​(BindingSetMapper<T> mapper)

      Maps the query result to a `Set`.

    - #### toSet

          public <T,​O> Set<O> toSet​(BindingSetMapper<T> mapper,
                                          MappingPostProcessor<T,​O> postProcessor)

      Maps the query result to a `Set`.

    - #### toMap

          public <K,​V> Map<K,​V> toMap​(Function<BindingSet,​K> keyMapper,
                                                  Function<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<BindingSet,​K> keyMapper,
                                                            Function<BindingSet,​V> valueMapper)

      Maps the query result to a `Map` of `Set`s.

    - #### toMapOfList

          public <K,​V> Map<K,​List<V>> toMapOfList​(Function<BindingSet,​K> keyMapper,
                                                              Function<BindingSet,​V> valueMapper)

      Maps the query result to a `Map` of `List`s.

    - #### 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<BindingSet,​Map.Entry<K,​V>> entryMapper)

      Maps the query result to a `Map`, throwing an Exception if there are multiple values for one key.

    - #### toMapOfSet

          public <T,​K,​V> Map<K,​Set<V>> toMapOfSet​(BindingSetMapper<T> mapper,
                                                                    Function<T,​K> keyMapper,
                                                                    Function<T,​V> valueMapper)

      Maps the query result to a `Map` of `Set`s.

    - #### toMapOfList

          public <T,​K,​V> Map<K,​List<V>> toMapOfList​(BindingSetMapper<T> mapper,
                                                                      Function<T,​K> keyMapper,
                                                                      Function<T,​V> valueMapper)

      Maps the query result to a `Map` of `List`s.

    - #### getBindingStream

          public Stream<BindingSet> getBindingStream​(TupleQueryResult result)

      If the result has only one empty binding set, this method returns an empty stream, otherwise the stream of BindingSets