org.eclipse.rdf4j.repository

## Class RepositoryResult<T>

- java.lang.Object
- - org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<T,RepositoryException>
  - - org.eclipse.rdf4j.repository.RepositoryResult<T>

- All Implemented Interfaces:
    AutoCloseable, Iterable<T>, CloseableIteration<T,RepositoryException>, Iteration<T,RepositoryException>

      public class RepositoryResult<T>
      extends AbstractCloseableIteration<T,RepositoryException>
      implements Iterable<T>

  A RepositoryResult is a result collection of objects (for example `Statement` , `Namespace`, or `Resource` objects) that can be iterated over. It keeps an open connection to the backend for lazy retrieval of individual results. Additionally it has some utility methods to fetch all results and add them to a collection.

  By default, a RepositoryResult is not necessarily a (mathematical) set: it may contain duplicate objects. Duplicate filtering can be `switched on`, but this should not be used lightly as the filtering mechanism is potentially memory-intensive.

  A RepositoryResult needs to be `closed` after use to free up any resources (open connections, read locks, etc.) it has on the underlying repository.

  Author:
    Jeen Broekstra, Arjohn Kampman
  See Also:
    `RepositoryConnection.getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.URI, org.eclipse.rdf4j.model.Value, boolean, org.eclipse.rdf4j.model.Resource[])`, `RepositoryConnection.getNamespaces()`, `RepositoryConnection.getContextIDs()`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RepositoryResult(CloseableIteration<? extends T,RepositoryException> iter)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `<C extends Collection<T>> C` | `addTo(C collection)` Deprecated. Use `Iterations.addAll(Iteration, Collection)` instead.
    `List<T>` | `asList()` Deprecated. Use `Iterations.asList(Iteration)` instead.
    `void` | `enableDuplicateFilter()` Switches on duplicate filtering while iterating over objects.
    `protected void` | `handleClose()` Called by `AbstractCloseableIteration.close()` when it is called for the first time.
    `boolean` | `hasNext()` Returns `true` if the iteration has more elements.
    `Iterator<T>` | `iterator()`
    `T` | `next()` Returns the next element in the iteration.
    `void` | `remove()` Removes from the underlying collection the last element returned by the iteration (optional operation).

    - ### Methods inherited from class org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration

      `close, isClosed`

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

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

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

    - ### Methods inherited from interface org.eclipse.rdf4j.common.iteration.Iteration

      `stream`

- - ### Constructor Detail

    - #### RepositoryResult

          public RepositoryResult(CloseableIteration<? extends T,RepositoryException> iter)

  - ### Method Detail

    - #### hasNext

          public boolean hasNext()
                          throws RepositoryException

      Description copied from interface: `Iteration`
      Returns `true` if the iteration has more elements. (In other words, returns `true` if `Iteration.next()` would return an element rather than throwing a `NoSuchElementException`.)
      Specified by:
        `hasNext` in interface `Iteration<T,RepositoryException>`
      Returns:
        `true` if the iteration has more elements.
      Throws:
        `RepositoryException`

    - #### next

          public T next()
                 throws RepositoryException

      Description copied from interface: `Iteration`
      Returns the next element in the iteration.
      Specified by:
        `next` in interface `Iteration<T,RepositoryException>`
      Returns:
        the next element in the iteration.
      Throws:
        `RepositoryException`

    - #### remove

          public void remove()
                      throws RepositoryException

      Description copied from interface: `Iteration`
      Removes from the underlying collection the last element returned by the iteration (optional operation). This method can be called only once per call to next.
      Specified by:
        `remove` in interface `Iteration<T,RepositoryException>`
      Throws:
        `RepositoryException`

    - #### handleClose

          protected void handleClose()
                              throws RepositoryException

      Description copied from class: `AbstractCloseableIteration`
      Called by `AbstractCloseableIteration.close()` when it is called for the first time. This method is only called once on each iteration. By default, this method does nothing.
      Overrides:
        `handleClose` in class `AbstractCloseableIteration<T,RepositoryException>`
      Throws:
        `RepositoryException`

    - #### enableDuplicateFilter

          public void enableDuplicateFilter()
                                     throws RepositoryException

      Switches on duplicate filtering while iterating over objects. The RepositoryResult will keep track of the previously returned objects in a `Set` and on calling next() or hasNext() will ignore any objects that already occur in this Set.

      Caution: use of this filtering mechanism is potentially memory-intensive.

      Throws:
        `RepositoryException` - if a problem occurred during initialization of the filter.

    - #### asList

          @Deprecated
          public List<T> asList()
                                     throws RepositoryException

      Deprecated. Use `Iterations.asList(Iteration)` instead.
      Returns a `List` containing all objects of this RepositoryResult in order of iteration. The RepositoryResult is fully consumed and automatically closed by this operation.

      Note: use this method with caution! It pulls the entire RepositoryResult in memory and as such is potentially very memory-intensive.

      Returns:
        a List containing all objects of this RepositoryResult.
      Throws:
        `RepositoryException` - if a problem occurred during retrieval of the results.
      See Also:
        `addTo(Collection)`

    - #### addTo

          @Deprecated
          public <C extends Collection<T>> C addTo(C collection)
                                                        throws RepositoryException

      Deprecated. Use `Iterations.addAll(Iteration, Collection)` instead.
      Adds all objects of this RepositoryResult to the supplied collection. The RepositoryResult is fully consumed and automatically closed by this operation.
      Returns:
        A reference to the collection that was supplied.
      Throws:
        `RepositoryException` - if a problem occurred during retrieval of the results.

    - #### iterator

          public Iterator<T> iterator()

      Specified by:
        `iterator` in interface `Iterable<T>`

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.