/** * Create a batch of nodes around the supplied iterable container. Note that the supplied iterator is accessed lazily only * when the batch is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @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 batch of nodes; never null */ public static Batch batchOfKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final RepositoryCache repository ) { if (keys == null) return emptyBatch(workspaceName, 1); return batchOfKeys(keys.iterator(), keys.size(), score, workspaceName, repository); }
/** * Create a batch of nodes around the supplied iterable container. Note that the supplied iterator is accessed lazily only * when the batch is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes to be returned; if null, an {@link #emptySequence empty instance} is * returned * @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 batch of nodes; never null */ public static Batch batchOfKeys( final Collection<NodeKey> keys, final float score, final String workspaceName, final RepositoryCache repository ) { if (keys == null) return emptyBatch(workspaceName, 1); return batchOfKeys(keys.iterator(), keys.size(), score, workspaceName, repository); }
/** * 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 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)); }
/** * Create a batch of nodes around the supplied iterator. Note that the supplied iterator is accessed lazily only when the * batch is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes 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 * @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 batch of nodes; never null */ public static Batch batchOfKeys( final Iterator<NodeKey> keys, final long nodeCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert nodeCount >= -1; if (keys == null) return emptyBatch(workspaceName, 1); final NodeCache cache = repository.getWorkspaceCache(workspaceName); return batchOfKeys(keys, nodeCount, score, workspaceName, cache); }
/** * Create a batch of nodes around the supplied iterator. Note that the supplied iterator is accessed lazily only when the * batch is {@link Batch#nextRow() used}. * * @param keys the iterator over the keys of the nodes 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 * @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 batch of nodes; never null */ public static Batch batchOfKeys( final Iterator<NodeKey> keys, final long nodeCount, final float score, final String workspaceName, final RepositoryCache repository ) { assert nodeCount >= -1; if (keys == null) return emptyBatch(workspaceName, 1); final NodeCache cache = repository.getWorkspaceCache(workspaceName); return batchOfKeys(keys, nodeCount, score, workspaceName, cache); }
@Override public Batch nextBatch() { if (currentBatch == null) { if (!more) { // make sure we always close close(); return null; } readBatch(); } Batch nextBatch = NodeSequence.batchOfKeys(currentBatch.keys().iterator(), currentBatch.scores().iterator(), currentBatch.size(), workspaceName, repo); currentBatch = null; return nextBatch; }
@Override public Batch nextBatch() { if (currentBatch == null) { if (!more) { // make sure we always close close(); return null; } readBatch(); } Batch nextBatch = NodeSequence.batchOfKeys(currentBatch.keys().iterator(), currentBatch.scores().iterator(), currentBatch.size(), workspaceName, repo); currentBatch = null; return nextBatch; }
protected NodeSequence multipleBatchesOf( Iterator<NodeKey> keys, float score, int sizeOfBatches ) { List<NodeKey> listOfKeys = new ArrayList<>(); List<Batch> batches = new ArrayList<>(); while (keys.hasNext()) { for (int i = 0; i != sizeOfBatches; ++i) { if (!keys.hasNext()) break; listOfKeys.add(keys.next()); } batches.add(NodeSequence.batchOfKeys(listOfKeys.iterator(), listOfKeys.size(), score, workspaceName(), cache)); listOfKeys = new ArrayList<>(); } return NodeSequence.withBatches(batches, 1); }