// Path: driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/traversal/step/map/OrientClassCountStep.java
// public class OrientClassCountStep<S> extends AbstractStep<S, Long> {
// 
//   private final boolean vertexStep;
//   private List<String> klasses;
// 
//   protected boolean done = false;
// 
//   public OrientClassCountStep(Traversal.Admin traversal, List<String> klasses, boolean vertexStep) {
//     super(traversal);
//     this.klasses = klasses;
//     this.vertexStep = vertexStep;
//   }
// 
//   @Override
//   protected Traverser.Admin<Long> processNextStart() throws NoSuchElementException {
//     if (!done) {
//       done = true;
//       ODatabaseDocument db = getDatabase();
//       Long v =
//           klasses.stream()
//               .filter(this::filterClass)
//               .mapToLong((klass) -> db.countClass(klass))
//               .reduce(0, (a, b) -> a + b);
//       return this.traversal.getTraverserGenerator().generate(v, (Step) this, 1L);
//     } else {
//       throw FastNoSuchElementException.instance();
//     }
//   }
// 
//   private ODatabaseDocument getDatabase() {
//     OGraph graph = (OGraph) this.traversal.getGraph().get();
//     return graph.getRawDatabase();
//   }
// 
//   private boolean filterClass(String klass) {
// 
//     ODatabaseDocument database = getDatabase();
//     OSchema schema = database.getMetadata().getSchema();
//     OClass schemaClass = schema.getClass(klass);
// 
//     if (vertexStep) {
//       return schemaClass.isSubClassOf("V");
//     } else {
//       return schemaClass.isSubClassOf("E");
//     }
//   }
// 
//   public List<String> getKlasses() {
//     return klasses;
//   }
// }


import static org.junit.Assert.assertEquals;
import java.util.Collections;
import org.apache.tinkerpop.gremlin.orientdb.traversal.step.map.OrientClassCountStep;
import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
package org.apache.tinkerpop.gremlin.orientdb;



public class OrientGraphCountStrategyTest {

  @Test
  public void shouldUseGlobalCountStepWithV() {
    OrientGraph graph = OrientGraph.open();

    try {
      GraphTraversalSource traversal = graph.traversal();

      GraphTraversal.Admin<Vertex, Long> admin = traversal.V().count().asAdmin();

      admin.applyStrategies();

      Step<Vertex, ?> startStep = admin.getStartStep();
// Path: driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/traversal/step/map/OrientClassCountStep.java
// public class OrientClassCountStep<S> extends AbstractStep<S, Long> {
// 
//   private final boolean vertexStep;
//   private List<String> klasses;
// 
//   protected boolean done = false;
// 
//   public OrientClassCountStep(Traversal.Admin traversal, List<String> klasses, boolean vertexStep) {
//     super(traversal);
//     this.klasses = klasses;
//     this.vertexStep = vertexStep;
//   }
// 
//   @Override
//   protected Traverser.Admin<Long> processNextStart() throws NoSuchElementException {
//     if (!done) {
//       done = true;
//       ODatabaseDocument db = getDatabase();
//       Long v =
//           klasses.stream()
//               .filter(this::filterClass)
//               .mapToLong((klass) -> db.countClass(klass))
//               .reduce(0, (a, b) -> a + b);
//       return this.traversal.getTraverserGenerator().generate(v, (Step) this, 1L);
//     } else {
//       throw FastNoSuchElementException.instance();
//     }
//   }
// 
//   private ODatabaseDocument getDatabase() {
//     OGraph graph = (OGraph) this.traversal.getGraph().get();
//     return graph.getRawDatabase();
//   }
// 
//   private boolean filterClass(String klass) {
// 
//     ODatabaseDocument database = getDatabase();
//     OSchema schema = database.getMetadata().getSchema();
//     OClass schemaClass = schema.getClass(klass);
// 
//     if (vertexStep) {
//       return schemaClass.isSubClassOf("V");
//     } else {
//       return schemaClass.isSubClassOf("E");
//     }
//   }
// 
//   public List<String> getKlasses() {
//     return klasses;
//   }
// }


// Path: driver/src/test/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraphCountStrategyTest.java
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import org.apache.tinkerpop.gremlin.orientdb.traversal.step.map.OrientClassCountStep;
import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;

package org.apache.tinkerpop.gremlin.orientdb;



public class OrientGraphCountStrategyTest {

  @Test
  public void shouldUseGlobalCountStepWithV() {
    OrientGraph graph = OrientGraph.open();

    try {
      GraphTraversalSource traversal = graph.traversal();

      GraphTraversal.Admin<Vertex, Long> admin = traversal.V().count().asAdmin();

      admin.applyStrategies();

      Step<Vertex, ?> startStep = admin.getStartStep();
      assertEquals(OrientClassCountStep.class, startStep.getClass());