public static Optional<ImmutableQueryModifiers> merge(ImmutableQueryModifiers parentQueryModifiers,
                                                          ImmutableQueryModifiers subqueryModifers) {

        if (areMergeable(parentQueryModifiers, subqueryModifers)) {
            return Optional.of(
                    new ImmutableQueryModifiersImpl(
                            parentQueryModifiers.isDistinct() || subqueryModifers.isDistinct(),
                            mergeLimits(
                                    parentQueryModifiers.getLimit(),
                                    subqueryModifers.getLimit()
                            ),
                            mergeOffsets(
                                    parentQueryModifiers.getOffset(),
                                    subqueryModifers.getOffset()
                            ),
                            mergeSortConditions(
                                    parentQueryModifiers.getSortConditions(),
                                    subqueryModifers.getSortConditions()
                            )));

        }
        return Optional.empty();
    }
public static Optional < ImmutableQueryModifiers > merge ( ImmutableQueryModifiers parentQueryModifiers , ImmutableQueryModifiers subqueryModifers ) { if ( areMergeable ( parentQueryModifiers , subqueryModifers ) ) { return Optional . of ( new ImmutableQueryModifiersImpl ( parentQueryModifiers . isDistinct ( ) || subqueryModifers . isDistinct ( ) , mergeLimits ( parentQueryModifiers . getLimit ( ) , subqueryModifers . getLimit ( ) ) , mergeOffsets ( parentQueryModifiers . getOffset ( ) , subqueryModifers . getOffset ( ) ) , mergeSortConditions ( parentQueryModifiers . getSortConditions ( ) , subqueryModifers . getSortConditions ( ) ) ) ) ; } return Optional . empty ( ) ; }
Merge two successively applied set of quantifiers (without intermediate operation)
Due to possible interactions,
a conservative approach is adopted.
<p>
Let p be the parent query modifiers, and s be the subquery modifiers.
If both p and s have more than one modifier within (OFFSET, LIMIT, ORDER or DISTINCT),
or if they have each exactly one,
but these are not of the same type,
then merging fails.