Class DroolsAbstractUniConstraintStream<Solution_,​A>

    • Method Detail

      • join

        public <B> BiConstraintStream<A,​B> join​(UniConstraintStream<B> otherStream,
                                                      BiJoiner<A,​B> joiner)
        Description copied from interface: UniConstraintStream
        Create a new BiConstraintStream for every combination of A and B for which the BiJoiner is true (for the properties it extracts from both facts).

        Important: This is faster and more scalable than a join followed by a filter, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks every combination of A and B.

        Specified by:
        join in interface UniConstraintStream<Solution_>
        Type Parameters:
        B - the type of the second matched fact
        Parameters:
        otherStream - never null
        joiner - never null
        Returns:
        never null, a stream that matches every combination of A and B for which the BiJoiner is true
      • join

        public <B> BiConstraintStream<A,​B> join​(Class<B> otherClass,
                                                      BiJoiner<A,​B>... joiners)
        Description copied from interface: UniConstraintStream
        As defined by UniConstraintStream.join(Class, BiJoiner). For performance reasons, the indexing joiners must be placed before filtering joiners.

        This method causes Unchecked generics array creation for varargs parameter warnings, but we can't fix it with a SafeVarargs annotation because it's an interface method. Therefore, there are overloaded methods with up to 4 BiJoiner parameters.

        Specified by:
        join in interface UniConstraintStream<Solution_>
        Type Parameters:
        B - the type of the second matched fact
        Parameters:
        otherClass - never null
        joiners - never null
        Returns:
        never null, a stream that matches every combination of A and B for which all the joiners are true
      • groupBy

        public <ResultContainerA_,​ResultA_,​ResultContainerB_,​ResultB_> BiConstraintStream<ResultA_,​ResultB_> groupBy​(UniConstraintCollector<A,​ResultContainerA_,​ResultA_> collectorA,
                                                                                                                                             UniConstraintCollector<A,​ResultContainerB_,​ResultB_> collectorB)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a BiConstraintStream, containing only a single tuple, the result of applying two UniConstraintCollectors.
        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        ResultContainerA_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultA_ - the type of the first fact in the destination BiConstraintStream's tuple
        ResultContainerB_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultB_ - the type of the second fact in the destination BiConstraintStream's tuple
        Parameters:
        collectorA - never null, the collector to perform the first grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorB - never null, the collector to perform the second grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <ResultContainerA_,​ResultA_,​ResultContainerB_,​ResultB_,​ResultContainerC_,​ResultC_> TriConstraintStream<ResultA_,​ResultB_,​ResultC_> groupBy​(UniConstraintCollector<A,​ResultContainerA_,​ResultA_> collectorA,
                                                                                                                                                                                                    UniConstraintCollector<A,​ResultContainerB_,​ResultB_> collectorB,
                                                                                                                                                                                                    UniConstraintCollector<A,​ResultContainerC_,​ResultC_> collectorC)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a TriConstraintStream, containing only a single tuple, the result of applying three UniConstraintCollectors.
        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        ResultContainerA_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultA_ - the type of the first fact in the destination TriConstraintStream's tuple
        ResultContainerB_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultB_ - the type of the second fact in the destination TriConstraintStream's tuple
        ResultContainerC_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultC_ - the type of the third fact in the destination TriConstraintStream's tuple
        Parameters:
        collectorA - never null, the collector to perform the first grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorB - never null, the collector to perform the second grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorC - never null, the collector to perform the third grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <ResultContainerA_,​ResultA_,​ResultContainerB_,​ResultB_,​ResultContainerC_,​ResultC_,​ResultContainerD_,​ResultD_> QuadConstraintStream<ResultA_,​ResultB_,​ResultC_,​ResultD_> groupBy​(UniConstraintCollector<A,​ResultContainerA_,​ResultA_> collectorA,
                                                                                                                                                                                                                                                           UniConstraintCollector<A,​ResultContainerB_,​ResultB_> collectorB,
                                                                                                                                                                                                                                                           UniConstraintCollector<A,​ResultContainerC_,​ResultC_> collectorC,
                                                                                                                                                                                                                                                           UniConstraintCollector<A,​ResultContainerD_,​ResultD_> collectorD)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a QuadConstraintStream, containing only a single tuple, the result of applying four UniConstraintCollectors.
        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        ResultContainerA_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultA_ - the type of the first fact in the destination QuadConstraintStream's tuple
        ResultContainerB_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultB_ - the type of the second fact in the destination QuadConstraintStream's tuple
        ResultContainerC_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultC_ - the type of the third fact in the destination QuadConstraintStream's tuple
        ResultContainerD_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultD_ - the type of the fourth fact in the destination QuadConstraintStream's tuple
        Parameters:
        collectorA - never null, the collector to perform the first grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorB - never null, the collector to perform the second grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorC - never null, the collector to perform the third grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorD - never null, the collector to perform the fourth grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <GroupKey_,​ResultContainer_,​Result_> BiConstraintStream<GroupKey_,​Result_> groupBy​(Function<A,​GroupKey_> groupKeyMapping,
                                                                                                                    UniConstraintCollector<A,​ResultContainer_,​Result_> collector)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a BiConstraintStream, consisting of unique tuples with two facts.

        The first fact is the return value of the group key mapping function, applied on the incoming tuple. The second fact is the return value of a given UniConstraintCollector applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKey_ - the type of the first fact in the destination BiConstraintStream's tuple
        ResultContainer_ - the mutable accumulation type (often hidden as an implementation detail)
        Result_ - the type of the second fact in the destination BiConstraintStream's tuple
        Parameters:
        groupKeyMapping - never null, function to convert the fact in the original tuple to a different fact
        collector - never null, the collector to perform the grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <GroupKey_,​ResultContainerB_,​ResultB_,​ResultContainerC_,​ResultC_> TriConstraintStream<GroupKey_,​ResultB_,​ResultC_> groupBy​(Function<A,​GroupKey_> groupKeyMapping,
                                                                                                                                                                              UniConstraintCollector<A,​ResultContainerB_,​ResultB_> collectorB,
                                                                                                                                                                              UniConstraintCollector<A,​ResultContainerC_,​ResultC_> collectorC)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a TriConstraintStream, consisting of unique tuples with three facts.

        The first fact is the return value of the group key mapping function, applied on the incoming tuple. The remaining facts are the return value of the respective UniConstraintCollector applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKey_ - the type of the first fact in the destination TriConstraintStream's tuple
        ResultContainerB_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultB_ - the type of the second fact in the destination TriConstraintStream's tuple
        ResultContainerC_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultC_ - the type of the third fact in the destination TriConstraintStream's tuple
        Parameters:
        groupKeyMapping - never null, function to convert the fact in the original tuple to a different fact
        collectorB - never null, the collector to perform the first grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorC - never null, the collector to perform the second grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <GroupKey_,​ResultContainerB_,​ResultB_,​ResultContainerC_,​ResultC_,​ResultContainerD_,​ResultD_> QuadConstraintStream<GroupKey_,​ResultB_,​ResultC_,​ResultD_> groupBy​(Function<A,​GroupKey_> groupKeyMapping,
                                                                                                                                                                                                                                     UniConstraintCollector<A,​ResultContainerB_,​ResultB_> collectorB,
                                                                                                                                                                                                                                     UniConstraintCollector<A,​ResultContainerC_,​ResultC_> collectorC,
                                                                                                                                                                                                                                     UniConstraintCollector<A,​ResultContainerD_,​ResultD_> collectorD)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a QuadConstraintStream, consisting of unique tuples with four facts.

        The first fact is the return value of the group key mapping function, applied on the incoming tuple. The remaining facts are the return value of the respective UniConstraintCollector applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKey_ - the type of the first fact in the destination QuadConstraintStream's tuple
        ResultContainerB_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultB_ - the type of the second fact in the destination QuadConstraintStream's tuple
        ResultContainerC_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultC_ - the type of the third fact in the destination QuadConstraintStream's tuple
        ResultContainerD_ - the mutable accumulation type (often hidden as an implementation detail)
        ResultD_ - the type of the fourth fact in the destination QuadConstraintStream's tuple
        Parameters:
        groupKeyMapping - never null, function to convert the fact in the original tuple to a different fact
        collectorB - never null, the collector to perform the first grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorC - never null, the collector to perform the second grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        collectorD - never null, the collector to perform the third grouping operation with See ConstraintCollectors for common operations, such as count(), sum() and others.
        Returns:
        never null
      • groupBy

        public <GroupKeyA_,​GroupKeyB_> BiConstraintStream<GroupKeyA_,​GroupKeyB_> groupBy​(Function<A,​GroupKeyA_> groupKeyAMapping,
                                                                                                     Function<A,​GroupKeyB_> groupKeyBMapping)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a BiConstraintStream, consisting of unique tuples with two facts.

        The first fact is the return value of the first group key mapping function, applied on the incoming tuple. The second fact is the return value of the second group key mapping function, applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKeyA_ - the type of the first fact in the destination BiConstraintStream's tuple
        GroupKeyB_ - the type of the second fact in the destination BiConstraintStream's tuple
        Parameters:
        groupKeyAMapping - never null, function to convert the original tuple into a first fact
        groupKeyBMapping - never null, function to convert the original tuple into a second fact
        Returns:
        never null
      • groupBy

        public <GroupKeyA_,​GroupKeyB_,​GroupKeyC_> TriConstraintStream<GroupKeyA_,​GroupKeyB_,​GroupKeyC_> groupBy​(Function<A,​GroupKeyA_> groupKeyAMapping,
                                                                                                                                        Function<A,​GroupKeyB_> groupKeyBMapping,
                                                                                                                                        Function<A,​GroupKeyC_> groupKeyCMapping)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a TriConstraintStream, consisting of unique tuples with three facts.

        The first fact is the return value of the first group key mapping function, applied on the incoming tuple. The second fact is the return value of the second group key mapping function, applied on all incoming tuples with the same first fact. The third fact is the return value of the third group key mapping function, applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKeyA_ - the type of the first fact in the destination TriConstraintStream's tuple
        GroupKeyB_ - the type of the second fact in the destination TriConstraintStream's tuple
        GroupKeyC_ - the type of the third fact in the destination TriConstraintStream's tuple
        Parameters:
        groupKeyAMapping - never null, function to convert the original tuple into a first fact
        groupKeyBMapping - never null, function to convert the original tuple into a second fact
        groupKeyCMapping - never null, function to convert the original tuple into a third fact
        Returns:
        never null
      • groupBy

        public <GroupKeyA_,​GroupKeyB_,​GroupKeyC_,​GroupKeyD_> QuadConstraintStream<GroupKeyA_,​GroupKeyB_,​GroupKeyC_,​GroupKeyD_> groupBy​(Function<A,​GroupKeyA_> groupKeyAMapping,
                                                                                                                                                                           Function<A,​GroupKeyB_> groupKeyBMapping,
                                                                                                                                                                           Function<A,​GroupKeyC_> groupKeyCMapping,
                                                                                                                                                                           Function<A,​GroupKeyD_> groupKeyDMapping)
        Description copied from interface: UniConstraintStream
        Convert the UniConstraintStream to a QuadConstraintStream, consisting of unique tuples with four facts.

        The first fact is the return value of the first group key mapping function, applied on the incoming tuple. The second fact is the return value of the second group key mapping function, applied on all incoming tuples with the same first fact. The third fact is the return value of the third group key mapping function, applied on all incoming tuples with the same first fact. The fourth fact is the return value of the fourth group key mapping function, applied on all incoming tuples with the same first fact.

        Specified by:
        groupBy in interface UniConstraintStream<Solution_>
        Type Parameters:
        GroupKeyA_ - the type of the first fact in the destination QuadConstraintStream's tuple
        GroupKeyB_ - the type of the second fact in the destination QuadConstraintStream's tuple
        GroupKeyC_ - the type of the third fact in the destination QuadConstraintStream's tuple
        GroupKeyD_ - the type of the fourth fact in the destination QuadConstraintStream's tuple
        Parameters:
        groupKeyAMapping - * calling map(Person::getAge) on such stream will produce a stream of Integers * [20, 25, 30],
        groupKeyBMapping - never null, function to convert the original tuple into a second fact
        groupKeyCMapping - never null, function to convert the original tuple into a third fact
        groupKeyDMapping - never null, function to convert the original tuple into a fourth fact
        Returns:
        never null
      • map

        public <ResultA_> UniConstraintStream<ResultA_> map​(Function<A,​ResultA_> mapping)
        Description copied from interface: UniConstraintStream
        Transforms the stream in such a way that tuples are remapped using the given function. This may produce a stream with duplicate tuples. See UniConstraintStream.distinct() for details. There are several recommendations for implementing the mapping function:
        • Purity. The mapping function should only depend on its input. That is, given the same input, it always returns the same output.
        • Bijectivity. No two input tuples should map to the same output tuple, or to tuples that are equal. Not following this recommendation creates a constraint stream with duplicate tuples, and may force you to use UniConstraintStream.distinct() later, which comes with a performance cost.
        • Immutable data carriers. The objects returned by the mapping function should be identified by their contents and nothing else. If two of them have contents which equal, then they should likewise equal and preferably be the same instance. The objects returned by the mapping function should also be immutable, meaning their contents should not be allowed to change.

        Simple example: assuming a constraint stream of tuples of Persons [Ann(age = 20), Beth(age = 25), Cathy(age = 30)], calling map(Person::getAge) on such stream will produce a stream of Integers [20, 25, 30],

        Example with a non-bijective mapping function: assuming a constraint stream of tuples of Persons [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)], calling map(Person::getAge) on such stream will produce a stream of Integers [20, 25, 30, 30, 20].

        Specified by:
        map in interface UniConstraintStream<Solution_>
        Type Parameters:
        ResultA_ - the type of the only fact in the resulting UniConstraintStream's tuple
        Parameters:
        mapping - never null, function to convert the original tuple into the new tuple
        Returns:
        never null
      • flattenLast

        public <ResultA_> UniConstraintStream<ResultA_> flattenLast​(Function<A,​Iterable<ResultA_>> mapping)
        Description copied from interface: UniConstraintStream
        Takes each tuple and applies a mapping on it, which turns the tuple into a Iterable. Returns a constraint stream consisting of contents of those iterables. This may produce a stream with duplicate tuples. See UniConstraintStream.distinct() for details.

        In cases where the original tuple is already an Iterable, use Function.identity() as the argument.

        Simple example: assuming a constraint stream of tuples of Persons [Ann(roles = [USER, ADMIN]]), Beth(roles = [USER]), Cathy(roles = [ADMIN, AUDITOR])], calling flattenLast(Person::getRoles) on such stream will produce a stream of [USER, ADMIN, USER, ADMIN, AUDITOR].

        Specified by:
        flattenLast in interface UniConstraintStream<Solution_>
        Type Parameters:
        ResultA_ - the type of facts in the resulting tuples
        Parameters:
        mapping - never null, function to convert the original tuple into Iterable
        Returns:
        never null