@Test public void shouldCreateLimitedSequenceSmallerThanDelegate() { assertThat(countRows(NodeSequence.limit(allNodes(), 2)), is(2L)); }
/** * Create a sequence of nodes that skips a specified number of nodes before returning any nodes and that limits the number of * nodes returned. * * @param sequence the original sequence that is to be limited; may be null * @param limitAndOffset the specification of the offset and limit; if null this method simply returns <code>sequence</code> * @return the limitd sequence of nodes; never null */ public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); // Perform the skip first ... if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } // And then the offset ... if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }
/** * Create a sequence of nodes that skips a specified number of nodes before returning any nodes and that limits the number of * nodes returned. * * @param sequence the original sequence that is to be limited; may be null * @param limitAndOffset the specification of the offset and limit; if null this method simply returns <code>sequence</code> * @return the limitd sequence of nodes; never null */ public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); // Perform the skip first ... if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } // And then the offset ... if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }
@Test public void shouldCreateLimitedSequenceSameSizeAsDelegateDelegateWhenLimitIsLarger() { long countAll = countRows(allNodes()); assertThat(countRows(NodeSequence.limit(allNodes(), countAll + 1)), is(countAll)); }
@Test public void shouldCreateLimitedSequenceSameSizeAsDelegateDelegate() { long countAll = countRows(allNodes()); assertThat(countRows(NodeSequence.limit(allNodes(), countAll)), is(countAll)); }
rows = NodeSequence.limit(rows, limit);
rows = NodeSequence.limit(rows, limit);