本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.Direction类的典型用法代码示例。如果您正苦于以下问题:Java Direction类的具体用法?Java Direction怎么用?Java Direction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Direction类属于org.apache.tinkerpop.gremlin.structure包,在下文中一共展示了Direction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReturnOutThenInOnVertexIterator
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
@Test
public void testReturnOutThenInOnVertexIterator() {
UUID factID = mockFact(null);
UUID inVertexObjectID = mockObject();
UUID outVertexObjectID = mockObject();
Edge edge = new FactEdge(getActGraph(), factID, inVertexObjectID, outVertexObjectID);
assertEquals(outVertexObjectID, edge.outVertex().id());
assertEquals(inVertexObjectID, edge.inVertex().id());
Iterator<Vertex> vertices = edge.vertices(Direction.BOTH);
assertTrue(vertices.hasNext());
assertEquals(outVertexObjectID, vertices.next().id());
assertTrue(vertices.hasNext());
assertEquals(inVertexObjectID, vertices.next().id());
assertFalse(vertices.hasNext());
}
示例2: addEdge
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
/**
* Add the given edge, from the given gremlin vertex, to the vertices selected by the given {@link
* AnyTraversal}.
*/
public <E extends Edge> Edge addEdge(E edge, org.apache.tinkerpop.gremlin.structure.Vertex from,
AnyTraversal anyTraversal) {
if (from == null) {
throw Edge.Exceptions.missingEdgeVertex(Direction.OUT, edge, from);
}
List<Vertex> tos = query.by(anyTraversal).list(Vertex.class);
if (tos == null || tos.isEmpty()) {
throw Edge.Exceptions.missingEdgeVertex(Direction.IN, edge, anyTraversal);
}
tos.forEach(to -> {
edge.to(to);
addEdge(edge, from, to.delegate());
});
return edge;
}
示例3: getEdges
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public static Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List<Edge> edges = new ArrayList<>();
if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
if (vertex.outEdges != null) {
if (edgeLabels.length == 0)
vertex.outEdges.values().forEach(edges::addAll);
else if (edgeLabels.length == 1)
edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
else
Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
}
}
if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
if (vertex.inEdges != null) {
if (edgeLabels.length == 0)
vertex.inEdges.values().forEach(edges::addAll);
else if (edgeLabels.length == 1)
edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
else
Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
}
}
return (Iterator) edges.iterator();
}
示例4: getVertices
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public static Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List<Vertex> vertices = new ArrayList<>();
if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
if (vertex.outEdges != null) {
if (edgeLabels.length == 0)
vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)));
else if (edgeLabels.length == 1)
vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
else
Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
}
}
if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
if (vertex.inEdges != null) {
if (edgeLabels.length == 0)
vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)));
else if (edgeLabels.length == 1)
vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
else
Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
}
}
return (Iterator) vertices.iterator();
}
示例5: specificEdges
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
@Override
protected Iterator<Edge> specificEdges(Direction direction, String... edgeLabels) {
List<Iterator<?>> iterators = new LinkedList<>();
if (edgeLabels.length == 0) {
edgeLabels = ALL_EDGES;
}
for (String label : edgeLabels) {
if (label == WrittenBy.label) {
if (direction == Direction.IN || direction == Direction.BOTH) {
iterators.add(getWrittenByIn().iterator());
}
} else if (label == SungBy.label) {
if (direction == Direction.IN || direction == Direction.BOTH) {
iterators.add(getSungByIn().iterator());
}
}
}
Iterator<Edge>[] iteratorsArray = iterators.toArray(new Iterator[iterators.size()]);
return IteratorUtils.concat(iteratorsArray);
}
示例6: getEdges
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public List<EdgeBean> getEdges(UUID vertexId, Direction dir, String[] edgeLabels) {
RetryDetails retryDetails = new RetryDetails();
List<EdgeBean> ans;
try {
do {
beginRead(retryDetails, true);
VertexBean vBean = vertices.get(vertexId);
ans = adjMap.getEdges(vBean, dir, edgeLabels);
} while (shouldRetryRead(retryDetails));
} finally {
endRead(retryDetails);
}
return ans;
}
示例7: getParents
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public Set<Parent> getParents(final Vertex vertex, final String identifierKey) {
Set<Parent> parentSet = new HashSet<>();
vertex.edges(Direction.OUT, PARENT_EDGE_LABEL).forEachRemaining(edge -> {
String parentIdentifier = getPropertyOrFail(edge.inVertex(), identifierKey);
Attribute scope;
Parent parent;
try {
scope = JSON_UTILS.deserialize((String) edge.property(SCOPE_PROPERTY_KEY).value(), Attribute.class);
// use ParentEntity ?
parent = new Parent(parentIdentifier, Sets.newHashSet(scope));
} catch (Exception e) {
LOGGER.debug("Error deserializing attribute", e);
parent = new Parent(parentIdentifier);
}
parentSet.add(parent);
});
return parentSet;
}
示例8: edges
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public Iterable<Edge> edges() {
Iterable<Edge> in = null;
Iterable<Edge> out = null;
if(direction==Direction.IN || direction==Direction.BOTH) {
if(vertex.getRole()==TripleComponentRole.OBJECT || vertex.getInternalId()<=vertex.getHDTGraph().getBaseGraph().getDictionary().getNshared()) {
in = getEdges(new TripleID(0,0,vertex.getInternalId()));
}
}
if(direction==Direction.OUT || direction==Direction.BOTH) {
if(vertex.getRole()==TripleComponentRole.SUBJECT || vertex.getInternalId()<=vertex.getHDTGraph().getBaseGraph().getDictionary().getNshared()) {
out = getEdges(new TripleID(vertex.getInternalId(),0,0));
}
}
if(in!=null && out!=null) {
return IteratorConcat.concat(in, out);
} else if(in!=null) {
return in;
} else if(out!=null){
return out;
}
return Collections.emptySet();
}
示例9: vertices
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
public Iterable<Vertex> vertices() {
Iterable<Vertex> in = null;
Iterable<Vertex> out = null;
if(direction==Direction.IN || direction==Direction.BOTH) {
if(vertex.getRole()==TripleComponentRole.OBJECT || vertex.getInternalId()<=vertex.getHDTGraph().getBaseGraph().getDictionary().getNshared()) {
in = Iter.mapIterable(getEdges(new TripleID(0,0,vertex.getInternalId())), new EdgeToVertex(Direction.OUT));
}
}
if(direction==Direction.OUT || direction==Direction.BOTH) {
if(vertex.getRole()==TripleComponentRole.SUBJECT || vertex.getInternalId()<=vertex.getHDTGraph().getBaseGraph().getDictionary().getNshared()) {
out = Iter.mapIterable(getEdges(new TripleID(vertex.getInternalId(),0,0)), new EdgeToVertex(Direction.IN));
}
}
if(in!=null && out!=null) {
return IteratorConcat.concat(in, out);
} else if(in!=null) {
return in;
} else if(out!=null){
return out;
}
return Collections.emptySet();
}
示例10: edgesFromVertex
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
/**
* @see {@link Templates#EDGES_FROM_VERTEX}
*/
String edgesFromVertex(final BlazeVertex src, final Direction dir,
final List<URI> edgeLabels) {
final URI id = src.rdfId();
final StringBuilder vc = buildValuesClause(
new StringBuilder(), "?src", asList(id));
if (!edgeLabels.isEmpty()) {
buildValuesClause(vc, "?label", edgeLabels);
}
final String queryStr;
if (dir == Direction.BOTH) {
queryStr = EDGES_FROM_VERTEX_BOTH.replace(Templates.VALUES, vc.toString());
} else {
final String DIRECTION = dir == Direction.OUT ? FORWARD : REVERSE;
queryStr = EDGES_FROM_VERTEX.replace(Templates.VALUES, vc.toString())
.replace(Templates.DIRECTION, DIRECTION);
}
return queryStr;
}
示例11: shouldConstructDetachedEdgeAsReference
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
@Test
@LoadGraphWith(GraphData.MODERN)
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
public void shouldConstructDetachedEdgeAsReference() {
g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("year", 2002);
final DetachedEdge detachedEdge = DetachedFactory.detach(g.E(convertToEdgeId("marko", "knows", "vadas")).next(), false);
assertEquals(convertToEdgeId("marko", "knows", "vadas"), detachedEdge.id());
assertEquals("knows", detachedEdge.label());
assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.OUT).next().getClass());
assertEquals(convertToVertexId("marko"), detachedEdge.vertices(Direction.OUT).next().id());
assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());
assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.IN).next().getClass());
assertEquals(convertToVertexId("vadas"), detachedEdge.vertices(Direction.IN).next().id());
assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());
assertEquals(0, IteratorUtils.count(detachedEdge.properties()));
}
示例12: edgeRelationTraversal
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
private GraphTraversal<Element, Vertex> edgeRelationTraversal(
GraknTx graph, Direction direction, Schema.EdgeProperty roleProperty, Collection<Var> vars) {
GraphTraversal<Element, Edge> edgeTraversal = Fragments.isEdge(__.identity());
// Filter by any provided type labels
applyLabelsToTraversal(edgeTraversal, roleProperty, roleLabels(), graph);
applyLabelsToTraversal(edgeTraversal, RELATIONSHIP_TYPE_LABEL_ID, relationTypeLabels(), graph);
traverseToRole(edgeTraversal, role(), roleProperty, vars);
// Identify the relation - role-player pair by combining the relationship edge and direction into a map
edgeTraversal.as(RELATION_EDGE.name()).constant(direction).as(RELATION_DIRECTION.name());
edgeTraversal.select(Pop.last, RELATION_EDGE.name(), RELATION_DIRECTION.name()).as(edge().name()).select(RELATION_EDGE.name());
return edgeTraversal.toV(direction);
}
示例13: shouldHashAndEqualsCorrectly
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldHashAndEqualsCorrectly() {
final Vertex gremlin = g.V(convertToVertexId("gremlin")).next();
final StarGraph gremlinStarGraph = StarGraph.of(gremlin);
final StarGraph.StarVertex gremlinStar = gremlinStarGraph.getStarVertex();
final Vertex marko = g.V(convertToVertexId("marko")).next();
final StarGraph markoStarGraph = StarGraph.of(marko);
final StarGraph.StarAdjacentVertex gremlinStarAdjacentGraph = (StarGraph.StarAdjacentVertex) IteratorUtils.filter(markoStarGraph.getStarVertex().edges(Direction.OUT, "uses"), x -> x.inVertex().id().equals(convertToVertexId("gremlin"))).next().inVertex();
final Set<Vertex> set = new HashSet<>();
for (int i = 0; i < 100; i++) {
set.add(gremlin);
set.add(gremlinStar);
set.add(gremlinStarAdjacentGraph);
}
assertEquals(1, set.size());
}
示例14: edgeRelationTraversal
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
private GraphTraversal<Vertex, Edge> edgeRelationTraversal(
GraknTx graph, Direction direction, Schema.EdgeProperty roleProperty, Collection<Var> vars) {
GraphTraversal<Vertex, Edge> edgeTraversal = __.toE(direction, Schema.EdgeLabel.ATTRIBUTE.getLabel());
// Identify the relation - role-player pair by combining the relationship edge and direction into a map
edgeTraversal.as(RELATION_EDGE.name()).constant(direction).as(RELATION_DIRECTION.name());
edgeTraversal.select(Pop.last, RELATION_EDGE.name(), RELATION_DIRECTION.name()).as(edge().name()).select(RELATION_EDGE.name());
// Filter by any provided type labels
applyLabelsToTraversal(edgeTraversal, roleProperty, roleLabels(), graph);
applyLabelsToTraversal(edgeTraversal, RELATIONSHIP_TYPE_LABEL_ID, relationTypeLabels(), graph);
traverseToRole(edgeTraversal, role(), roleProperty, vars);
return edgeTraversal;
}
示例15: writeVertices
import org.apache.tinkerpop.gremlin.structure.Direction; //导入依赖的package包/类
/**
* Writes a list of vertices in adjacency list format where vertices are written with edges from both
* directions. Under this serialization model, edges are grouped by label.
*
* @param outputStream the stream to write to.
* @param vertexIterator a traversal that returns a list of vertices.
* @param direction if direction is null then no edges are written.
*/
@Override
public void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator, final Direction direction) throws IOException {
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
if (wrapAdjacencyList) writer.write("{\"" + GraphSONTokens.VERTICES + "\":[");
while (vertexIterator.hasNext()) {
writeVertex(baos, vertexIterator.next(), direction);
writer.write(new String(baos.toByteArray()));
if (wrapAdjacencyList) {
if (vertexIterator.hasNext())
writer.write(",");
} else {
writer.newLine();
}
baos.reset();
}
if (wrapAdjacencyList) writer.write("]}");
}
writer.flush();
}