@Test public void shouldCreateLimitedSequenceSmallerThanDelegate() { assertThat(countRows(NodeSequence.limit(allNodes(), 2)), is(2L)); }
public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }
NodeSequence { public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; } }
NodeSequence { public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }  }
NodeSequence { public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }  abstract int width(); abstract long getRowCount(); abstract boolean isEmpty(); abstract Batch nextBatch(); abstract void close(); static NodeSequence emptySequence( final int width ); static Batch emptyBatch( final String workspaceName,
                                    final int width ); static NodeSequence withBatch( final Batch sequence ); static NodeSequence withBatches( final Collection<Batch> batches,
                                            final int width ); static NodeSequence withBatches( final Iterator<Batch> batches,
                                            final int width,
                                            final long rowCount ); static NodeSequence withNodes( final Collection<CachedNode> nodes,
                                          final float score,
                                          final String workspaceName ); static NodeSequence withNodes( final Iterator<CachedNode> nodes,
                                          final long nodeCount,
                                          final float score,
                                          final String workspaceName ); static NodeSequence withNode( final CachedNode node,
                                         final int width,
                                         final float score,
                                         final String workspaceName ); static NodeSequence withNodeKeys( final Collection<NodeKey> keys,
                                             final float score,
                                             final String workspaceName,
                                             final RepositoryCache repository ); static NodeSequence withNodeKeys( final Collection<NodeKey> keys,
                                             final float score,
                                             final String workspaceName,
                                             final NodeCache cache ); static NodeSequence withNodeKeys( final Iterator<NodeKey> keys,
                                             final long keyCount,
                                             final float score,
                                             final String workspaceName,
                                             final RepositoryCache repository ); static NodeSequence withNodeKeys( final Iterator<NodeKey> keys,
                                             final long keyCount,
                                             final float score,
                                             final String workspaceName,
                                             final NodeCache cache ); static NodeSequence limit( NodeSequence sequence,
                                      Limit limitAndOffset ); static NodeSequence limit( final NodeSequence sequence,
                                      final long maxRows ); static NodeSequence skip( final NodeSequence sequence,
                                     final int skip ); static NodeSequence filter( final NodeSequence sequence,
                                       final RowFilter filter ); static NodeSequence append( final NodeSequence first,
                                       final NodeSequence second ); static NodeSequence slice( final NodeSequence original,
                                      Columns columns ); static NodeSequence merging( final NodeSequence first,
                                        final NodeSequence second,
                                        final int totalWidth ); static Batch batchOf( final Collection<CachedNode> nodes,
                                 final float score,
                                 final String workspaceName ); static Batch batchOf( final Iterator<CachedNode> nodes,
                                 final long nodeCount,
                                 final float score,
                                 final String workspaceName ); static Batch batchOfKeys( final Collection<NodeKey> keys,
                                     final float score,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final long nodeCount,
                                     final float score,
                                     final String workspaceName,
                                     final NodeCache cache ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final long nodeCount,
                                     final float score,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final Iterator<Float> scores,
                                     final long nodeCount,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static RowFilter requireBoth( final RowFilter first,
                                         final RowFilter second ); static RowFilter requireEither( final RowFilter first,
                                           final RowFilter second ); static Batch batchFilteredWith( final Batch batch,
                                           final RowFilter filter ); static Batch batchWithCount( Batch batch ); static Batch copy( Batch batch ); }
NodeSequence { public static NodeSequence limit( NodeSequence sequence, Limit limitAndOffset ) { if (sequence == null) return emptySequence(0); if (limitAndOffset != null && !limitAndOffset.isUnlimited()) { final int limit = limitAndOffset.getRowLimit(); if (limitAndOffset.isOffset()) { sequence = skip(sequence, limitAndOffset.getOffset()); } if (limit != Integer.MAX_VALUE) { sequence = limit(sequence, limit); } } return sequence; }  abstract int width(); abstract long getRowCount(); abstract boolean isEmpty(); abstract Batch nextBatch(); abstract void close(); static NodeSequence emptySequence( final int width ); static Batch emptyBatch( final String workspaceName,
                                    final int width ); static NodeSequence withBatch( final Batch sequence ); static NodeSequence withBatches( final Collection<Batch> batches,
                                            final int width ); static NodeSequence withBatches( final Iterator<Batch> batches,
                                            final int width,
                                            final long rowCount ); static NodeSequence withNodes( final Collection<CachedNode> nodes,
                                          final float score,
                                          final String workspaceName ); static NodeSequence withNodes( final Iterator<CachedNode> nodes,
                                          final long nodeCount,
                                          final float score,
                                          final String workspaceName ); static NodeSequence withNode( final CachedNode node,
                                         final int width,
                                         final float score,
                                         final String workspaceName ); static NodeSequence withNodeKeys( final Collection<NodeKey> keys,
                                             final float score,
                                             final String workspaceName,
                                             final RepositoryCache repository ); static NodeSequence withNodeKeys( final Collection<NodeKey> keys,
                                             final float score,
                                             final String workspaceName,
                                             final NodeCache cache ); static NodeSequence withNodeKeys( final Iterator<NodeKey> keys,
                                             final long keyCount,
                                             final float score,
                                             final String workspaceName,
                                             final RepositoryCache repository ); static NodeSequence withNodeKeys( final Iterator<NodeKey> keys,
                                             final long keyCount,
                                             final float score,
                                             final String workspaceName,
                                             final NodeCache cache ); static NodeSequence limit( NodeSequence sequence,
                                      Limit limitAndOffset ); static NodeSequence limit( final NodeSequence sequence,
                                      final long maxRows ); static NodeSequence skip( final NodeSequence sequence,
                                     final int skip ); static NodeSequence filter( final NodeSequence sequence,
                                       final RowFilter filter ); static NodeSequence append( final NodeSequence first,
                                       final NodeSequence second ); static NodeSequence slice( final NodeSequence original,
                                      Columns columns ); static NodeSequence merging( final NodeSequence first,
                                        final NodeSequence second,
                                        final int totalWidth ); static Batch batchOf( final Collection<CachedNode> nodes,
                                 final float score,
                                 final String workspaceName ); static Batch batchOf( final Iterator<CachedNode> nodes,
                                 final long nodeCount,
                                 final float score,
                                 final String workspaceName ); static Batch batchOfKeys( final Collection<NodeKey> keys,
                                     final float score,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final long nodeCount,
                                     final float score,
                                     final String workspaceName,
                                     final NodeCache cache ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final long nodeCount,
                                     final float score,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static Batch batchOfKeys( final Iterator<NodeKey> keys,
                                     final Iterator<Float> scores,
                                     final long nodeCount,
                                     final String workspaceName,
                                     final RepositoryCache repository ); static RowFilter requireBoth( final RowFilter first,
                                         final RowFilter second ); static RowFilter requireEither( final RowFilter first,
                                           final RowFilter second ); static Batch batchFilteredWith( final Batch batch,
                                           final RowFilter filter ); static Batch batchWithCount( Batch batch ); static Batch copy( Batch batch ); static final RowFilter NO_PASS_ROW_FILTER; static final RowFilter PASS_ROW_FILTER; }