-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
880 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
blueprints-core/src/main/java/com/tinkerpop/blueprints/GraphQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.tinkerpop.blueprints; | ||
|
||
/** | ||
* (c) Matthias Broecheler (me@matthiasb.com) | ||
*/ | ||
|
||
public interface GraphQuery extends Query { | ||
|
||
@Override | ||
public GraphQuery has(final String key, final Object value); | ||
|
||
@Override | ||
public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare); | ||
|
||
@Override | ||
public <T extends Comparable<T>> GraphQuery interval(final String key, final T startValue, final T endValue); | ||
|
||
@Override | ||
public GraphQuery limit(final long max); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
blueprints-core/src/main/java/com/tinkerpop/blueprints/VertexQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.tinkerpop.blueprints; | ||
|
||
/** | ||
* A VertexQuery object defines a collection of filters and modifiers that are used to intelligently select edges from a vertex. | ||
* | ||
* @author Matthias Brocheler (http://matthiasb.com) | ||
* @author Marko A. Rodriguez (http://markorodriguez.com) | ||
*/ | ||
public interface VertexQuery extends Query { | ||
|
||
|
||
/** | ||
* The direction of the edges to retrieve. | ||
* | ||
* @param direction whether to retrieve the incoming, outgoing, or both directions | ||
* @return the modified query object | ||
*/ | ||
public VertexQuery direction(final Direction direction); | ||
|
||
/** | ||
* Filter out the edge if its label is not in set of provided labels. | ||
* | ||
* @param labels the labels to check against | ||
* @return the modified query object | ||
*/ | ||
public VertexQuery labels(final String... labels); | ||
|
||
/** | ||
* Execute the query and return the number of edges that are unfiltered. | ||
* | ||
* @return the number of unfiltered edges | ||
*/ | ||
public long count(); | ||
|
||
/** | ||
* Return the raw ids of the vertices on the other end of the edges. | ||
* | ||
* @return the raw ids of the vertices on the other end of the edges | ||
*/ | ||
public Object vertexIds(); | ||
|
||
|
||
@Override | ||
public VertexQuery has(final String key, final Object value); | ||
|
||
@Override | ||
public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare); | ||
|
||
@Override | ||
public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue); | ||
|
||
@Override | ||
public VertexQuery limit(final long max); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
blueprints-core/src/main/java/com/tinkerpop/blueprints/util/DefaultGraphQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package com.tinkerpop.blueprints.util; | ||
|
||
import com.tinkerpop.blueprints.Edge; | ||
import com.tinkerpop.blueprints.Element; | ||
import com.tinkerpop.blueprints.Graph; | ||
import com.tinkerpop.blueprints.GraphQuery; | ||
import com.tinkerpop.blueprints.Vertex; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* For those graph engines that do not support the low-level querying of the vertices or edges, then DefaultQuery can be used. | ||
* DefaultQuery assumes, at minimum, that Graph.getVertices() and Graph.getEdges() is implemented by the respective Graph. | ||
* | ||
* @author Marko A. Rodriguez (http://markorodriguez.com) | ||
*/ | ||
public class DefaultGraphQuery extends DefaultQuery implements GraphQuery { | ||
|
||
private final Graph graph; | ||
|
||
public DefaultGraphQuery(final Graph graph) { | ||
this.graph = graph; | ||
} | ||
|
||
public GraphQuery has(final String key, final Object value) { | ||
this.hasContainers.add(new HasContainer(key, value, Compare.EQUAL)); | ||
return this; | ||
} | ||
|
||
public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare) { | ||
this.hasContainers.add(new HasContainer(key, value, compare)); | ||
return this; | ||
} | ||
|
||
public <T extends Comparable<T>> GraphQuery 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 GraphQuery limit(final long max) { | ||
this.limit = max; | ||
return this; | ||
} | ||
|
||
public Iterable<Edge> edges() { | ||
return new DefaultGraphQueryIterable<Edge>(false); | ||
} | ||
|
||
public Iterable<Vertex> vertices() { | ||
return new DefaultGraphQueryIterable<Vertex>(true); | ||
} | ||
|
||
private class DefaultGraphQueryIterable<T extends Element> implements Iterable<T> { | ||
|
||
private Iterable<T> iterable = null; | ||
|
||
public DefaultGraphQueryIterable(final boolean forVertex) { | ||
for (final HasContainer hasContainer : hasContainers) { | ||
if (hasContainer.compare.equals(Compare.EQUAL)) { | ||
if (forVertex) | ||
this.iterable = (Iterable<T>) graph.getVertices(hasContainer.key, hasContainer.value); | ||
else | ||
this.iterable = (Iterable<T>) graph.getEdges(hasContainer.key, hasContainer.value); | ||
break; | ||
} | ||
} | ||
if (null == this.iterable) { | ||
if (forVertex) | ||
this.iterable = (Iterable<T>) graph.getVertices(); | ||
else | ||
this.iterable = (Iterable<T>) graph.getEdges(); | ||
} | ||
} | ||
|
||
public Iterator<T> iterator() { | ||
return new Iterator<T>() { | ||
T nextElement = null; | ||
final Iterator<T> itty = iterable.iterator(); | ||
long count = 0; | ||
|
||
public boolean hasNext() { | ||
if (null != this.nextElement) { | ||
return true; | ||
} else { | ||
return this.loadNext(); | ||
} | ||
} | ||
|
||
public T next() { | ||
while (true) { | ||
if (this.nextElement != null) { | ||
final T temp = this.nextElement; | ||
this.nextElement = null; | ||
return temp; | ||
} | ||
|
||
if (!this.loadNext()) | ||
throw new NoSuchElementException(); | ||
} | ||
} | ||
|
||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private boolean loadNext() { | ||
this.nextElement = null; | ||
if (count >= limit) return false; | ||
while (this.itty.hasNext()) { | ||
final T element = this.itty.next(); | ||
boolean filter = false; | ||
|
||
/*if (!forVertex) { | ||
filter = !containsLabel(((Edge) element).getLabel(), labels); | ||
}*/ | ||
|
||
//if (!filter) { | ||
for (final HasContainer hasContainer : hasContainers) { | ||
if (!hasContainer.isLegal(element)) { | ||
filter = true; | ||
break; | ||
} | ||
} | ||
//} | ||
if (!filter) { | ||
this.nextElement = element; | ||
this.count++; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
/*private boolean containsLabel(final String label, final String[] labels) { | ||
if (labels.length == 0) | ||
return true; | ||
for (final String temp : labels) { | ||
if (temp.equals(label)) | ||
return true; | ||
} | ||
return false; | ||
}*/ | ||
} | ||
|
||
} |
Oops, something went wrong.