/** * Create a sequence of nodes that iterates over the supplied batches of nodes. Note that the supplied iterator is accessed * lazily as the resulting sequence instance is {@link #nextBatch() used}. * * @param batches the iterable container containing the node batches to be returned; if null, an {@link #emptySequence empty * instance} is returned * @param width the width of the batch; must be positive * @return the sequence of nodes; never null */ public static NodeSequence withBatches( final Collection<Batch> batches, final int width ) { if (batches == null || batches.isEmpty()) return emptySequence(width); if (batches.size() == 1) { Batch batch = batches.iterator().next(); assert width == batch.width(); return withBatch(batch); } // Tally the size of each batch ... long rowCount = 0L; for (Batch batch : batches) { long count = batch.rowCount(); rowCount = count < 0L ? -1L : rowCount + count; } return withBatches(batches.iterator(), width, rowCount); }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the node keys to be returned; if null, an {@link #emptySequence empty instance} is returned * @param nodeCount the number of nodes in the iterator; must be -1 if not known, 0 if known to be empty, or a positive number * if the number of nodes is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Iterator<CachedNode> nodes, final long nodeCount, final float score, final String workspaceName ) { assert nodeCount >= -1; if (nodes == null) return emptySequence(1); return withBatch(batchOf(nodes, nodeCount, score, workspaceName)); }
/** * Create a sequence of nodes that iterates over the supplied batches of nodes. Note that the supplied iterator is accessed * lazily as the resulting sequence instance is {@link #nextBatch() used}. * * @param batches the iterable container containing the node batches to be returned; if null, an {@link #emptySequence empty * instance} is returned * @param width the width of the batch; must be positive * @return the sequence of nodes; never null */ public static NodeSequence withBatches( final Collection<Batch> batches, final int width ) { if (batches == null || batches.isEmpty()) return emptySequence(width); if (batches.size() == 1) { Batch batch = batches.iterator().next(); assert width == batch.width(); return withBatch(batch); } // Tally the size of each batch ... long rowCount = 0L; for (Batch batch : batches) { long count = batch.rowCount(); rowCount = count < 0L ? -1L : rowCount + count; } return withBatches(batches.iterator(), width, rowCount); }
/** * Obtain a {@link NodeSequence} that returns all (queryable) nodes in the workspace, where each node is assigned the given * score. * * @param score the score for each node * @param nodeCount the number of nodes (or an estimate) that will be returned * @return the sequence of nodes; never null */ public NodeSequence allNodes( float score, long nodeCount ) { // Use a single batch for the workspace content ... NodeCacheIterator iter = nodes(workspaceName, null); assert iter != null; Batch mainBatch = NodeSequence.batchOfKeys(iter, nodeCount, score, workspaceName, repo); // Nothing else to use ... return NodeSequence.withBatch(mainBatch); }
/** * Obtain a {@link NodeSequence} that returns all (queryable) nodes in the workspace, where each node is assigned the given * score. * * @param score the score for each node * @param nodeCount the number of nodes (or an estimate) that will be returned * @return the sequence of nodes; never null */ public NodeSequence allNodes( float score, long nodeCount ) { // Use a single batch for the workspace content ... NodeCacheIterator iter = nodes(workspaceName, null); assert iter != null; Batch mainBatch = NodeSequence.batchOfKeys(iter, nodeCount, score, workspaceName, repo); // Nothing else to use ... return NodeSequence.withBatch(mainBatch); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, repository)); }
/** * Create a sequence of nodes that iterates over the supplied nodes. Note that the supplied iterator is accessed lazily as the * resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param nodes the iterator over the node keys to be returned; if null, an {@link #emptySequence empty instance} is returned * @param nodeCount the number of nodes in the iterator; must be -1 if not known, 0 if known to be empty, or a positive number * if the number of nodes is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @return the sequence of nodes; never null */ public static NodeSequence withNodes( final Iterator<CachedNode> nodes, final long nodeCount, final float score, final String workspaceName ) { assert nodeCount >= -1; if (nodes == null) return emptySequence(1); return withBatch(batchOf(nodes, nodeCount, score, workspaceName)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the node cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final NodeCache cache ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, cache)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param cache the node cache used to access the cached nodes; may be null only if the key sequence is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final NodeCache cache ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, cache)); }
/** * Create a sequence of nodes that iterates over the supplied node keys. Note that the supplied iterator is accessed lazily as * the resulting sequence's {@link #nextBatch() first batch} is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the node keys to be returned; if null, an {@link #emptySequence empty instance} * is returned * @param keyCount the number of node keys in the iterator; must be -1 if not known, 0 if known to be empty, or a positive * number if the number of node keys is known * @param score the score to return for all of the nodes * @param workspaceName the name of the workspace in which all of the nodes exist * @param repository the repository cache used to access the workspaces and cached nodes; may be null only if the key sequence * is null or empty * @return the sequence of nodes; never null */ public static NodeSequence withNodeKeys( final Iterator<NodeKey> keys, final long keyCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert keyCount >= -1; if (keys == null) return emptySequence(1); return withBatch(batchOfKeys(keys, keyCount, score, workspaceName, repository)); }