com.tinkerpop.blueprints.util.DefaultQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blueprints-core Show documentation
Show all versions of blueprints-core Show documentation
Core interfaces and utilities for Blueprints
package com.tinkerpop.blueprints.util;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Query;
import com.tinkerpop.blueprints.Vertex;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* For those graph engines that do not support the low-level querying of the edges of a vertex, then DefaultQuery can be used.
* DefaultQuery assumes, at minimum, that Vertex.getOutEdges() and Vertex.getInEdges() is implemented by the respective Graph.
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class DefaultQuery implements Query {
private static final String[] EMPTY_LABELS = new String[]{};
private final Vertex vertex;
public Direction direction = Direction.BOTH;
public String[] labels = EMPTY_LABELS;
public long limit = Long.MAX_VALUE;
public List hasContainers = new ArrayList();
public DefaultQuery(final Vertex vertex) {
this.vertex = vertex;
}
public Query has(final String key, final Object value) {
this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL));
return this;
}
public > Query has(final String key, final T value, final Compare compare) {
this.hasContainers.add(new HasContainer(key, value, compare));
return this;
}
public > Query interval(final String key, final T startValue, final T endValue) {
this.hasContainers.add(new HasContainer(key, startValue, Compare.GREATER_THAN_EQUAL));
this.hasContainers.add(new HasContainer(key, endValue, Compare.LESS_THAN));
return this;
}
public Query direction(final Direction direction) {
this.direction = direction;
return this;
}
public Query labels(final String... labels) {
this.labels = labels;
return this;
}
public Query limit(final long max) {
this.limit = max;
return this;
}
public Iterable edges() {
return new DefaultQueryIterable(false);
}
public Iterable vertices() {
return new DefaultQueryIterable(true);
}
public long count() {
long count = 0;
for (final Edge edge : this.edges()) {
count++;
}
return count;
}
public Object vertexIds() {
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy