private ImmutableList < UnaryOperatorNode > extractModifierNodes ( IntermediateQueryFactory iqFactory ) { long correctedOffset = offset > 0 ? offset : 0 ; Optional < SliceNode > sliceNode = Optional . of ( limit ) . filter ( l -> l >= 0 ) . map ( l -> Optional . of ( iqFactory . createSliceNode ( correctedOffset , l ) ) ) . orElseGet ( ( ) -> Optional . of ( correctedOffset ) . filter ( o -> o > 0 ) . map ( iqFactory :: createSliceNode ) ) ; Optional < UnaryOperatorNode > distinctNode = isDistinct ( ) ? Optional . of ( iqFactory . createDistinctNode ( ) ) : Optional . empty ( ) ; ImmutableList < OrderByNode . OrderComparator > orderComparators = getSortConditions ( ) . stream ( ) . map ( o -> iqFactory . createOrderComparator ( o . getVariable ( ) , o . getDirection ( ) == OrderCondition . ORDER_ASCENDING ) ) . collect ( ImmutableCollectors . toList ( ) ) ; Optional < UnaryOperatorNode > orderByNode = orderComparators . isEmpty ( ) ? Optional . empty ( ) : Optional . of ( iqFactory . createOrderByNode ( orderComparators ) ) ; return Stream . of ( sliceNode , distinctNode , orderByNode ) . filter ( Optional :: isPresent ) . map ( Optional :: get ) . collect ( ImmutableCollectors . toList ( ) ) ; }
Top - down order