Class QueryJinqStream<T>

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.stream.BaseStream<T,​java.util.stream.Stream<T>>, java.util.stream.Stream<T>, JinqStream<T>

    public class QueryJinqStream<T>
    extends NonQueryJinqStream<T>
    implements JinqStream<T>
    • Method Detail

      • where

        public <E extends java.lang.Exception> JinqStream<T> where​(JinqStream.Where<T,​E> test)
        Description copied from interface: JinqStream
        Filters the elements of the stream.
         JinqStream<Customer> stream = ...;
         JinqStream<Customer> result = stream.where(c -> c.getName().equals("Alice"));
         
         
        Specified by:
        where in interface JinqStream<T>
        Overrides:
        where in class NonQueryJinqStream<T>
        Parameters:
        test - function applied to the elements of the stream. When passed an element from the stream, the function should return true if the element should be kept. if the function returns false, the element is discarded.
        Returns:
        a new stream that returns only the elements satisfying the filter
      • where

        public <E extends java.lang.Exception> JinqStream<T> where​(JinqStream.WhereWithSource<T,​E> test)
        Description copied from interface: JinqStream
        Filters the elements of the stream. This version allows the filter function to take a second parameter with an InQueryStreamSource. This lets the function create new streams of elements that it can use in subqueries.
        Specified by:
        where in interface JinqStream<T>
        Overrides:
        where in class NonQueryJinqStream<T>
        Parameters:
        test - function applied to each element of the stream. The function is passed an element from the stream as well as an InQueryStreamSource. The function should return true if the element should be kept. if the function returns false, the element is discarded.
        Returns:
        a new stream that returns only the elements satisfying the filter
        See Also:
        JinqStream.where(Where)
      • select

        public <U> JinqStream<U> select​(JinqStream.Select<T,​U> select)
        Description copied from interface: JinqStream
        Transforms the elements in the stream. The method allows you to rewrite each element from the stream, so that they contain only certain fields or to do some calculation based on the values of the fields.
         JinqStream<Customer> stream = ...;
         JinqStream<String> result = stream.select(c -> c.getName());
         
         
        Specified by:
        select in interface JinqStream<T>
        Overrides:
        select in class NonQueryJinqStream<T>
        Parameters:
        select - function applied to the elements of the stream. When passed an element from the stream, the function should return a new value that should be used instead of the element in the stream.
        Returns:
        a new stream that uses only the new rewritten stream elements
      • selectAll

        public <U> JinqStream<U> selectAll​(JinqStream.Join<T,​U> select)
        Description copied from interface: JinqStream
        Transforms the elements in the stream. The method allows you to rewrite each element from the stream, so that they contain only certain fields or to do some calculation based on the values of the fields. Unlike a normal select(), this method allows you to return a stream of elements. The stream elements will all be added to the final stream.
         JinqStream<Country> stream = ...;
         JinqStream<City> result = stream.selectAll(c -> JinqStream.from(c.getCities()));
         
         
        Specified by:
        selectAll in interface JinqStream<T>
        Overrides:
        selectAll in class NonQueryJinqStream<T>
        Parameters:
        select - function applied to the elements of the stream. When passed an element from the stream, the function should return a stream of new values that will be flattened and placed in the new stream
        Returns:
        a new stream that uses only the new rewritten stream elements
        See Also:
        JinqStream.select(Select)
      • selectAllList

        public <U> JinqStream<U> selectAllList​(JinqStream.JoinToIterable<T,​U> select)
        Description copied from interface: JinqStream
        A variant of selectAll() that can be used if you want to join to a collection without the trouble of converting it to a JinqStream first.
         JinqStream<Country> stream = ...;
         JinqStream<City> result = stream.selectAll(c -> c.getCities());
         
         
        Specified by:
        selectAllList in interface JinqStream<T>
        Overrides:
        selectAllList in class NonQueryJinqStream<T>
        Parameters:
        select - function applied to the elements of the stream. When passed an element from the stream, the function should return a collection of new values that will be flattened and placed in the new stream
        Returns:
        a new stream that uses only the new rewritten stream elements
        See Also:
        JinqStream.selectAll(Join)
      • join

        public <U> JinqStream<Pair<T,​U>> join​(JinqStream.Join<T,​U> join)
        Description copied from interface: JinqStream
        Pairs up each entry of the stream with a stream of related elements.
         JinqStream<Country> stream = ...;
         JinqStream<Pair<Country, City>> result = 
            stream.join(c -> JinqStream.from(c.getCities()));
         
         
        Specified by:
        join in interface JinqStream<T>
        Overrides:
        join in class NonQueryJinqStream<T>
        Parameters:
        join - function applied to the elements of the stream. When passed an element from the stream, the function should return a stream of values that should be paired up with that stream element.
        Returns:
        a new stream with the paired up elements
      • leftOuterJoin

        public <U> JinqStream<Pair<T,​U>> leftOuterJoin​(JinqStream.Join<T,​U> join)
        Description copied from interface: JinqStream
        Pairs up each entry of the stream with a stream of related elements. Uses a left outer join during the pairing up process, so even if an element is not joined with anything, a pair will still be created in the output stream consisting of the element paired with null.
         JinqStream<Country> stream = ...;
         JinqStream<Pair<Country, Mountain>> result = 
            stream.leftOuterJoin(c -> JinqStream.from(c.getMountain()));
         JinqStream<Pair<Country, Mountain>> result = 
            stream.leftOuterJoin(c -> JinqStream.of(c.getHighestMountain()));
         
         
        Specified by:
        leftOuterJoin in interface JinqStream<T>
        Overrides:
        leftOuterJoin in class NonQueryJinqStream<T>
        Parameters:
        join - function applied to the elements of the stream. When passed an element from the stream, the function should return a stream of values that should be paired up with that stream element. The function must use a JPA association or navigational link as the base for the stream returned. Both singular or plural associations are allowed.
        Returns:
        a new stream with the paired up elements
        See Also:
        JinqStream.join(Join)
      • leftOuterJoin

        public <U> JinqStream<Pair<T,​U>> leftOuterJoin​(JinqStream.JoinWithSource<T,​U> join,
                                                             JinqStream.WhereForOn<T,​U> on)
        Description copied from interface: JinqStream
        Pairs up each entry of the stream with a stream of related elements. Uses a left outer join during the pairing up process, so even if an element is not joined with anything, a pair will still be created in the output stream consisting of the element paired with null. This version also passes an InQueryStreamSource to the join function so that the function can join elements with unrelated streams of entities from a database and an ON clause can be specified that will determine which elements from the two streams will be joined together.
         JinqStream<Country> stream = ...;
         JinqStream<Pair<Country, Mountain>> result = 
            stream.leftOuterJoin(
                    (c, source) -> source.stream(Mountain.class), 
                    (country, mountain) -> country.getName().equals(mountain.getCountry()));
         
         
        Specified by:
        leftOuterJoin in interface JinqStream<T>
        Overrides:
        leftOuterJoin in class NonQueryJinqStream<T>
        Parameters:
        join - function applied to the elements of the stream. When passed an element from the stream, the function should return a stream of values that should be paired up with that stream element. The function must use a JPA association or navigational link as the base for the stream returned. Both singular or plural associations are allowed.
        on - this is a comparison function that returns true if the elements from the two streams should be joined together. It is similar to a standard where() clause except that the elements from the two streams are passed in as separate parameters for convenience (as opposed to being passed in as a pair)
        Returns:
        a new stream with the paired up elements
        See Also:
        JinqStream.leftOuterJoin(Join)
      • crossJoin

        public <U> JinqStream<Pair<T,​U>> crossJoin​(JinqStream<U> join)
        Description copied from interface: JinqStream
        Performs a full cross-join of the elements of two streams.
        Specified by:
        crossJoin in interface JinqStream<T>
        Overrides:
        crossJoin in class NonQueryJinqStream<T>
        Parameters:
        join - other stream to perform the cross join with
        Returns:
        a new stream where each element of the stream is paired up with each element of the join stream
      • count

        public long count()
        Description copied from interface: JinqStream
        Counts the elements in the stream. If the stream contains only a single field of data (i.e. not a tuple) as derived from a database query, then the count will be of non-NULL elements only. If the stream contains more than one field of data (i.e. a tuple) or if the stream is streaming in-memory data, then the count will include NULL values.
        Specified by:
        count in interface JinqStream<T>
        Specified by:
        count in interface java.util.stream.Stream<T>
        Overrides:
        count in class LazyWrappedStream<T>
        See Also:
        Stream.count()
      • sumInteger

        public java.lang.Long sumInteger​(JinqStream.CollectInteger<T> aggregate)
        Description copied from interface: JinqStream
        Calculates a sum over the elements of a stream. Different sum methods are provided for calculating the sum of integer, long, double, BigDecimal, and BigInteger values.
         JinqStream<City> stream = ...;
         long totalPopulation = stream.sumInteger(c -> c.getPopulation()); 
         
         
        Specified by:
        sumInteger in interface JinqStream<T>
        Overrides:
        sumInteger in class NonQueryJinqStream<T>
        Parameters:
        aggregate - function applied to each element of the stream. When passed an element of the stream, it should return the value that should be added to the sum.
        Returns:
        the sum of the values returned by the function
      • max

        public <V extends java.lang.Comparable<V>> V max​(JinqStream.CollectComparable<T,​V> aggregate)
        Description copied from interface: JinqStream
        Finds the largest or maximum element of a stream.
         JinqStream<Student> stream = ...;
         Date birthdayOfYoungest = stream.max(s -> s.getBirthday()); 
         
         
        Specified by:
        max in interface JinqStream<T>
        Overrides:
        max in class NonQueryJinqStream<T>
        Parameters:
        aggregate - function applied to each element of the stream. When passed an element of the stream, it should return the value that should be compared.
        Returns:
        the maximum of the values returned by the function
      • min

        public <V extends java.lang.Comparable<V>> V min​(JinqStream.CollectComparable<T,​V> aggregate)
        Description copied from interface: JinqStream
        Finds the smallest or minimum element of a stream.
         JinqStream<Student> stream = ...;
         Date birthdayOfOldest = stream.min(s -> s.getBirthday()); 
         
         
        Specified by:
        min in interface JinqStream<T>
        Overrides:
        min in class NonQueryJinqStream<T>
        Parameters:
        aggregate - function applied to each element of the stream. When passed an element of the stream, it should return the value that should be compared.
        Returns:
        the minimum of the values returned by the function
        See Also:
        JinqStream.max(CollectComparable)
      • avg

        public <V extends java.lang.Number & java.lang.Comparable<V>> java.lang.Double avg​(JinqStream.CollectNumber<T,​V> aggregate)
        Description copied from interface: JinqStream
        Finds the average of the elements of a stream.
         JinqStream<Student> stream = ...;
         double averageAge = stream.avg(s -> s.getage()); 
         
         
        Specified by:
        avg in interface JinqStream<T>
        Overrides:
        avg in class NonQueryJinqStream<T>
        Parameters:
        aggregate - function applied to each element of the stream. When passed an element of the stream, it should return the value that should be included in the average
        Returns:
        the average of the values returned by the function
      • sortedBy

        public <V extends java.lang.Comparable<V>> JinqStream<T> sortedBy​(JinqStream.CollectComparable<T,​V> sorter)
        Description copied from interface: JinqStream
        Sorts the elements of a stream in ascending order based on the value returned. The sort is stable, so it is possible to sort the stream multiple times in order to have multiple sort keys. The last sort becomes the primary sort key, and earlier sorts become lesser keys.
        Specified by:
        sortedBy in interface JinqStream<T>
        Overrides:
        sortedBy in class NonQueryJinqStream<T>
        Parameters:
        sorter - function applied to each element of the stream. When passed an element of the stream, it should return the value that should be used as the sorting value of the element
        Returns:
        sorted stream
      • getDebugQueryString

        public java.lang.String getDebugQueryString()
        Description copied from interface: JinqStream
        Returns the query that Jinq will send to the database to generate the values of the stream.
        Specified by:
        getDebugQueryString in interface JinqStream<T>
        Overrides:
        getDebugQueryString in class NonQueryJinqStream<T>
        Returns:
        the database query string or null if Jinq cannot find a database query equivalent to the contents of the stream.
      • setHint

        public JinqStream<T> setHint​(java.lang.String name,
                                     java.lang.Object value)
        Description copied from interface: JinqStream
        Sets a hint on the stream for how the query should be executed
        Specified by:
        setHint in interface JinqStream<T>
        Overrides:
        setHint in class NonQueryJinqStream<T>
        Parameters:
        name - name of the hint to change
        value - value to assign to the hint
        Returns:
        a pointer to the stream, to make it easier to chain method calls on the stream