Package org.openrdf.query.algebra.evaluation.cursors

Source Code of org.openrdf.query.algebra.evaluation.cursors.MultiProjectionCursor

/*
* Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2008.
*
* Licensed under the Aduna BSD-style license.
*/
package org.openrdf.query.algebra.evaluation.cursors;

import java.util.List;

import org.openrdf.cursor.Cursor;
import org.openrdf.cursor.DelegatingCursor;
import org.openrdf.query.BindingSet;
import org.openrdf.query.algebra.MultiProjection;
import org.openrdf.query.algebra.ProjectionElemList;
import org.openrdf.store.StoreException;

public class MultiProjectionCursor extends DelegatingCursor<BindingSet> {

  /*-----------*
   * Constants *
   *-----------*/

  private final List<ProjectionElemList> projections;

  private final BindingSet parentBindings;

  /*-----------*
   * Variables *
   *-----------*/

  private BindingSet currentBindings;

  private volatile int nextProjectionIdx;

  /*--------------*
   * Constructors *
   *--------------*/

  public MultiProjectionCursor(MultiProjection multiProjection, Cursor<BindingSet> cursor,
      BindingSet bindings)
  {
    super(cursor);
    this.projections = multiProjection.getProjections();
    this.parentBindings = bindings;
  }

  /*---------*
   * Methods *
   *---------*/

  @Override
  public BindingSet next()
    throws StoreException
  {
    int idx = nextProjectionIdx;

    if (currentBindings == null || idx >= projections.size()) {
      currentBindings = super.next();

      if (currentBindings == null) {
        return null;
      }

      idx = nextProjectionIdx = 0;
    }

    ProjectionElemList nextProjection = projections.get(idx);
    nextProjectionIdx++;

    return ProjectionCursor.project(nextProjection, currentBindings, parentBindings);
  }

  @Override
  public void close()
    throws StoreException
  {
    super.close();
    nextProjectionIdx = projections.size();
  }
}
TOP

Related Classes of org.openrdf.query.algebra.evaluation.cursors.MultiProjectionCursor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.