Java Code Examples for org.apache.tinkerpop.gremlin.structure.Vertex#edges()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Vertex#edges() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestVertexNavToEdges.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testFromVertexGetEdges() {
    Vertex v1 = sqlgGraph.addVertex();
    Vertex v2 = sqlgGraph.addVertex();
    Edge e = v1.addEdge("label1", v2, "name", "marko");
    sqlgGraph.tx().commit();
    assertDb(Topology.EDGE_PREFIX + "label1", 1);
    assertDb(Topology.VERTEX_PREFIX  +  "vertex", 2);

    Iterator<Edge> edges = v1.edges(Direction.BOTH, "label1");
    List<Edge> toList= IteratorUtils.toList(edges);
    assertEquals(1, toList.size());
    Edge edge = toList.get(0);
    assertEquals(e, edge);
    String name = edge.<String>property("name").value();
    assertEquals("marko", name);

    assertFalse(vertexTraversal(this.sqlgGraph, v1).inE("label1").hasNext());
    edge = vertexTraversal(this.sqlgGraph, v1).bothE("label1").next();
    assertEquals(e, edge);

    name = edge.<String>property("name").value();
    assertEquals("marko", name);
}
 
Example 2
Source File: VertexDuplicator.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
static void moveIncomingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) {
  for (Iterator<Edge> edges = vertex.edges(Direction.IN); edges.hasNext(); ) {
    Edge edge = edges.next();
    if (edge.label().equals(VERSION_OF)) {
      continue;
    }
    Edge duplicateEdge = edge.outVertex().addEdge(edge.label(), duplicate);
    for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
      Property<Object> property = properties.next();

      duplicateEdge.property(property.key(), property.value());
    }
    if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) {
      duplicateEdge.<String>property("tim_id")
        .ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge));
    }
    edge.remove();
  }
}
 
Example 3
Source File: MapInAdjacentVerticesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Getter.
 */
private static Map<String, WindupVertexFrame> handleGetter(Vertex vertex, Method method, Object[] arguments,
            MapInAdjacentVertices annotation, FramedGraph framedGraph)
{
    if (arguments != null && arguments.length != 0)
        throw new WindupException("Method must take zero arguments: " + method.getName());

    Map<String, WindupVertexFrame> result = new HashMap<>();
    Iterator<Edge> edges = vertex.edges(Direction.IN, annotation.label());
    while (edges.hasNext())
    {
        Edge edge = edges.next();
        Property<String> property = edge.property(annotation.mapKeyField());
        if (property == null)
            continue;

        Vertex v = edge.outVertex();
        WindupVertexFrame frame = framedGraph.frameElement(v, WindupVertexFrame.class);
        result.put(property.value(), frame);
    }
    return result;
}
 
Example 4
Source File: AllEdgesIterator.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
private Edge findNext() {
    TitanEdge rel = null;
    while (rel == null) {
        if (currentEdges.hasNext()) {
            rel = (TitanEdge)currentEdges.next();
            if (vertices != null && !vertices.contains(rel.vertex(Direction.IN)))
                rel = null;
        } else {
            if (vertexIter.hasNext()) {
                Vertex nextVertex = vertexIter.next();
                currentEdges = nextVertex.edges(Direction.OUT);
            } else break;
        }
    }
    return rel;
}
 
Example 5
Source File: TestLoadingAdjacent.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testLoadEdges() {
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "john1");
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "john2");
    Edge e = v1.addEdge("friend", v2, "weight", 1);
    this.sqlgGraph.tx().commit();

    Iterator<Edge> adjacents = v1.edges(Direction.OUT);

    Assert.assertTrue(adjacents.hasNext());

    Edge adjacent = adjacents.next();

    Assert.assertFalse(adjacents.hasNext());

    Assert.assertEquals(e.id(), adjacent.id());
    Assert.assertEquals(toList(e.properties()), toList(adjacent.properties()));
}
 
Example 6
Source File: HBaseSchemaTest.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testEdgeLabelAddProperty() {
    assertEquals(0, count(graph.vertices()));

    graph.createLabel(ElementType.VERTEX, "a", ValueType.STRING, "key0", ValueType.INT);
    graph.createLabel(ElementType.VERTEX, "b", ValueType.STRING, "key1", ValueType.INT);
    graph.createLabel(ElementType.VERTEX, "c", ValueType.STRING, "key2", ValueType.INT);
    graph.createLabel(ElementType.VERTEX, "d", ValueType.STRING, "key3", ValueType.INT);

    Vertex v1 = graph.addVertex(T.id, id(10), T.label, "a", "key0", 10);
    Vertex v2 = graph.addVertex(T.id, id(11), T.label, "b", "key1", 11);
    Vertex v3 = graph.addVertex(T.id, id(12), T.label, "c", "key2", 12);
    Vertex v4 = graph.addVertex(T.id, id(13), T.label, "d", "key3", 13);

    graph.createLabel(ElementType.EDGE, "knows", ValueType.STRING, "since", ValueType.DATE);
    graph.connectLabels("a", "knows", "b");

    Edge e = graph.addEdge(v1, v2, "knows", "since", LocalDate.now());

    Iterator<Edge> it = v1.edges(Direction.OUT, "knows");
    assertEquals(1, count(it));

    try {
        e.property("key3", "hi");
    } catch (HBaseGraphNotValidException ignored) {
    }

    graph.updateLabel(ElementType.EDGE, "knows", "key3", ValueType.STRING);
    e.property("key3", "hi");

    it = v1.edges(Direction.OUT, "knows");
    assertEquals(1, count(it));
}
 
Example 7
Source File: WomenWritersJsonCrudService.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(ReadEntityImpl entity, Vertex entityVertex) {
  Set<String> languages = new HashSet<>();
  final Iterator<Edge> isCreatorOf = entityVertex.edges(Direction.IN, "isCreatedBy");

  while (isCreatorOf.hasNext()) {
    final Edge next = isCreatorOf.next();
    final Boolean creatorOfIsAccepted = next.property("wwrelation_accepted").isPresent() ?
      (Boolean) next.property("wwrelation_accepted").value() : false;
    final Boolean creatorOfIsLatest = next.property("isLatest").isPresent() ?
      (Boolean) next.property("isLatest").value() : false;

    if (creatorOfIsAccepted && creatorOfIsLatest) {
      final Vertex publication = next.outVertex();
      final Iterator<Edge> hasWorkLanguage = publication.edges(Direction.OUT, "hasWorkLanguage");
      while (hasWorkLanguage.hasNext()) {
        final Edge nextLanguage = hasWorkLanguage.next();
        final Boolean languageIsAccepted = nextLanguage.property("wwrelation_accepted").isPresent() ?
          (Boolean) nextLanguage.property("wwrelation_accepted").value() : false;
        final Boolean languageIsLatest = nextLanguage.property("isLatest").isPresent() ?
          (Boolean) nextLanguage.property("isLatest").value() : false;

        if (languageIsAccepted && languageIsLatest) {
          final Vertex languageVertex = nextLanguage.inVertex();
          final String language = getProp(languageVertex, "wwlanguage_name", String.class).orElse(null);
          if (language != null) {
            languages.add(language);
          }
        }
      }
    }
  }
  entity.addExtraPoperty("languages", languages);
}
 
Example 8
Source File: Attachable.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
    final Edge baseEdge = attachableEdge.get();
    final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT, attachableEdge.get().label());
    while (edgeIterator.hasNext()) {
        final Edge edge = edgeIterator.next();
        if (ElementHelper.areEqual(edge, baseEdge))
            return Optional.of(edge);
    }
    return Optional.empty();
}
 
Example 9
Source File: WomenWritersJsonCrudService.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private List<Tuple<String, String>> getAuthorsForPublication(GraphTraversalSource traversalSource,
                                                             Vre vre,
                                                             Vertex vertex) {
  List<Tuple<String, String>> authors = new ArrayList<>();

  final Iterator<Edge> isCreatedBy = vertex.edges(Direction.OUT, "isCreatedBy");

  while (isCreatedBy.hasNext()) {
    final Edge next = isCreatedBy.next();
    final Boolean isAccepted = (Boolean) next.property("wwrelation_accepted").isPresent() ?
      (Boolean) next.property("wwrelation_accepted").value() : false;
    final Object isLatest = next.property("isLatest").isPresent() ?
      (Boolean) next.property("isLatest").value() : false;

    if (isAccepted && (Boolean) isLatest) {
      final Vertex author1 = next.inVertex();
      final Collection personCollection = vre.getCollectionForTypeName("wwperson");
      final String authorName = getDisplayname(traversalSource, author1, personCollection).orElse(null);
      String authorGender = getProp(author1, "wwperson_gender", String.class).orElse(null);
      if (authorGender != null) {
        authorGender = authorGender.replaceAll("\"", "");
      }
      if (authorName != null) {
        authors.add(tuple(authorName, authorGender));
      }
    }
  }
  return authors;
}
 
Example 10
Source File: TinkerGraphQuerySemaphoreNeighborInject.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Collection<TinkerGraphSemaphoreNeighborInjectMatch> evaluate() {
	final Collection<TinkerGraphSemaphoreNeighborInjectMatch> matches = new ArrayList<>();

	final Collection<Vertex> routes = driver.getVertices(ModelConstants.ROUTE);
	for (final Vertex route : routes) {
		final Iterable<Edge> entries = () -> route.edges(Direction.OUT, ModelConstants.ENTRY);
		for (final Edge edge : entries) {
			final Vertex semaphore = edge.inVertex();
			matches.add(new TinkerGraphSemaphoreNeighborInjectMatch(route, semaphore));
		}
	}

	return matches;
}
 
Example 11
Source File: Util.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
public static void dfs(Vertex node, Consumer<Vertex> vertexConsumer) {
  vertexConsumer.accept(node);
  Iterator<Edge> edges = node.edges(Direction.OUT, References.CHILD_OF);
  while (edges.hasNext()) {
    Edge edge = edges.next();
    dfs(edge.inVertex(), vertexConsumer);
  }
}
 
Example 12
Source File: ObjectVertexTest.java    From act-platform with ISC License 5 votes vote down vote up
@Test
public void testAppliesTimeFilterToSearch() {
  Long beforeTimestamp = 970000000L;
  Long afterTimestamp = 980000000L;

  ActGraph timeFilterGraph = createActGraph(TraverseParams.builder()
          .setAfterTimestamp(afterTimestamp)
          .setBeforeTimestamp(beforeTimestamp)
          .build());

  Vertex vertex = ObjectVertex.builder()
          .setGraph(timeFilterGraph)
          .setObjectRecord(new ObjectRecord().setTypeID(UUID.randomUUID()))
          .setObjectType(ObjectTypeStruct.builder().setName("someObjectType").setId(UUID.randomUUID()).build())
          .build();

  // Don't care about the answer
  when(getActGraph().getObjectFactDao().searchFacts(any()))
          .thenAnswer(invocation -> ResultContainer.<FactRecord>builder().build());

  // Fetching edges will trigger a search for facts
  vertex.edges(BOTH);

  verify(getObjectFactDao(), times(1)).searchFacts(argThat(criteria -> {
    assertEquals(afterTimestamp, criteria.getStartTimestamp());
    assertEquals(beforeTimestamp, criteria.getEndTimestamp());
    return true;
  }));
}
 
Example 13
Source File: Util.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
public static List<Vertex> children(Vertex vertex) {
  Iterator<Edge> edges = vertex.edges(Direction.OUT, References.CHILD_OF);
  List<Vertex> vertices = new ArrayList<>();
  while (edges.hasNext()) {
    Edge edge = edges.next();
    vertices.add(edge.inVertex());
  }
  return Collections.unmodifiableList(vertices);
}
 
Example 14
Source File: Util.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
public static Vertex parent(Vertex vertex) {
  Iterator<Edge> edges = vertex.edges(Direction.IN, References.CHILD_OF);
  if (!edges.hasNext()) {
    return null;
  }
  return edges.next().outVertex();
}
 
Example 15
Source File: Util.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
public static void dfs(Vertex node, BiConsumer<Vertex, Vertex> vertexConsumer) {
  Iterator<Edge> edges = node.edges(Direction.OUT, References.CHILD_OF);
  if (!edges.hasNext()) {
    vertexConsumer.accept(node, null);
  }
  while (edges.hasNext()) {
    Edge edge = edges.next();
    vertexConsumer.accept(node, edge.inVertex());
    dfs(edge.inVertex(), vertexConsumer);
  }
}
 
Example 16
Source File: BitsyGraphIT.java    From bitsy with Apache License 2.0 4 votes vote down vote up
public void testLargeDegreePerformance() {
    long ts = System.currentTimeMillis();

    Vertex one = graph.addVertex();
    one.property("one", "1");
    Object oneId = one.id();

    int numVertices = 10000; // 1000000;
    Object[] vids = new Object[numVertices];
    for (int i = 0; i < numVertices; i++) { // Change to 1M for perf
        Vertex many = graph.addVertex();
        many.property("many", "2");
        addEdge(graph, one, many, "toMany");
        vids[i] = many.id();

        if (i % 1000 == 0) {
            System.out.println(i + " 1000 in " + (System.currentTimeMillis() - ts));
            ts = System.currentTimeMillis();

            graph.tx().commit();
            one = graph.vertices(oneId).next();
        }
    }
    
    for (int i=0; i < numVertices; i++) {
        Vertex v = getVertex(graph, vids[i]);

        Iterator<Edge> iter = v.edges(Direction.BOTH);
        assertTrue(iter.hasNext());
        iter.next();
        assertFalse(iter.hasNext());

        v.remove();

        if (i % 1000 == 0) {
            System.out.println(i + " 1000 in " + (System.currentTimeMillis() - ts));
            
            if (i % 5000 == 0) {
                Iterator<Edge> iter2 = getVertex(graph, one.id()).edges(Direction.BOTH);
                for (int j=0; j < numVertices - i - 1; j++) {
                    assertTrue(iter2.hasNext());
                    iter2.next();
                }
                assertFalse(iter.hasNext());
            }
            
            ts = System.currentTimeMillis();

            graph.tx().commit();
        }
    }

    graph.tx().commit();
}
 
Example 17
Source File: GraphOMRSMetadataStore.java    From egeria with Apache License 2.0 4 votes vote down vote up
synchronized List<Relationship> getRelationshipsForEntity(String entityGUID)

            throws
            TypeErrorException,
            RepositoryErrorException
    {
        final String methodName = "getRelationshipsForEntity";

        List<Relationship> relationships = new ArrayList<>();

        // Look in the graph
        GraphTraversalSource g = instanceGraph.traversal();
        Iterator<Vertex> vi = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID);
        if (vi.hasNext()) {
            Vertex vertex = vi.next();
            log.debug("{} found entity vertex {}", methodName, vertex);

            Iterator<Edge> edges = vertex.edges(Direction.BOTH, "Relationship");
            log.debug("{} entity has these edges {}", methodName, edges);
            while (edges.hasNext()) {
                Edge edge = edges.next();
                log.debug("{} entity has edge {}", methodName, edge);

                Relationship relationship = new Relationship();
                relationshipMapper.mapEdgeToRelationship(edge, relationship);

                // Set the relationship ends...
                try {

                    vertex = edge.outVertex();

                    // Could test here whether each vertex is for a proxy, but it doesn't matter whether the vertex represents a full entity
                    // (i.e. EntityDetail of a local/reference copy) as opposed to an EntityProxy. It can be retrieved as a proxy anyway...

                    if (vertex != null) {
                        log.debug("{} entity vertex {}", methodName, vertex);
                        EntityProxy entityOneProxy = new EntityProxy();
                        entityMapper.mapVertexToEntityProxy(vertex, entityOneProxy);
                        log.debug("{} entityOneProxy {}", methodName, entityOneProxy);
                        relationship.setEntityOneProxy(entityOneProxy);
                    }

                    vertex = edge.inVertex();

                    if (vertex != null) {
                        log.debug("{} entity vertex {}", methodName, vertex);
                        EntityProxy entityTwoProxy = new EntityProxy();
                        entityMapper.mapVertexToEntityProxy(vertex, entityTwoProxy);
                        log.debug("{} entityTwoProxy {}", methodName, entityTwoProxy);
                        relationship.setEntityTwoProxy(entityTwoProxy);
                    }

                } catch (Exception e) {
                    log.error("{} Caught exception from entity mapper {}", methodName, e.getMessage());
                    g.tx().rollback();

                    throw new RepositoryErrorException(GraphOMRSErrorCode.RELATIONSHIP_NOT_FOUND.getMessageDefinition(entityMapper.getEntityGUID(vertex), methodName,
                                                                                                                      this.getClass().getName(),
                                                                                                                      repositoryName),
                            this.getClass().getName(),
                            methodName, e);
                }

                relationships.add(relationship);
            }
        }

        g.tx().commit();

        return relationships;
    }
 
Example 18
Source File: GraphOMRSMetadataStore.java    From egeria with Apache License 2.0 4 votes vote down vote up
synchronized void removeEntityFromStore(String entityGUID)
{
    final String methodName = "removeEntityFromStore";

    // Look in the graph
    String guid = entityGUID;
    GraphTraversalSource g = instanceGraph.traversal();

    GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID);

    // Only looking for non-proxy entities:
    gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, false);

    if (gt.hasNext()) {
        Vertex vertex = gt.next();

        Boolean isProxy = entityMapper.isProxy(vertex);
        if (!isProxy) {

            log.debug("{} found entity vertex {} to be removed", methodName, vertex);

            // Look for associated classifications.
            Iterator<Edge> classifierEdges = vertex.edges(Direction.OUT, "Classifier");
            while (classifierEdges.hasNext()) {
                Edge classifierEdge = classifierEdges.next();
                Vertex classificationVertex = classifierEdge.inVertex();
                // Get the classification's name for debug/info only
                Classification existingClassification = new Classification();
                try {
                    classificationMapper.mapVertexToClassification(classificationVertex, existingClassification);
                } catch (Exception e) {
                    log.error("{} caught exception from classification mapper for classification {}", methodName, existingClassification.getName());
                    // Nothing you can do - just keep going
                }
                log.debug("{} removing classification {} from entity", methodName, existingClassification.getName());
                classifierEdge.remove();
                classificationVertex.remove();
            }

            // Finally remove the entity vertex...
            vertex.remove();

            log.debug("{} removed entity vertex with guid {}", methodName, entityGUID);
        }
    }
    g.tx().commit();

}
 
Example 19
Source File: StarGraphTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_STRING_VALUES)
public void shouldHandleSelfLoops() {
    assertEquals(0l, IteratorUtils.count(graph.vertices()));
    assertEquals(0l, IteratorUtils.count(graph.edges()));
    final Vertex vertex = graph.addVertex("person");
    final VertexProperty<String> vertexProperty = vertex.property("name", "furnace");
    final Edge edge = vertex.addEdge("self", vertex);
    final Property<String> edgeProperty = edge.property("acl", "private");
    assertEquals(1l, IteratorUtils.count(graph.vertices()));
    assertEquals(1l, IteratorUtils.count(graph.edges()));
    assertEquals(1l, IteratorUtils.count(vertex.properties()));
    assertEquals(1l, IteratorUtils.count(edge.properties()));
    assertEquals(vertexProperty, vertex.properties().next());
    assertEquals(edgeProperty, edge.properties().next());
    ///
    final StarGraph starGraph = StarGraph.of(vertex);
    final StarGraph.StarVertex starVertex = starGraph.getStarVertex();
    final Edge starEdge = starVertex.edges(Direction.OUT).next();
    assertEquals(vertex, starVertex);
    assertEquals(edge, starEdge);
    assertEquals(1l, IteratorUtils.count(starVertex.properties()));
    assertEquals("furnace", starVertex.value("name"));
    assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH, "self")));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT, "self")));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN, "self")));
    Iterator<Vertex> vertexIterator = starVertex.vertices(Direction.BOTH, "self");
    assertEquals(starVertex, vertexIterator.next());
    assertEquals(starVertex, vertexIterator.next());
    assertFalse(vertexIterator.hasNext());
    assertEquals(starVertex, starVertex.vertices(Direction.OUT, "self").next());
    assertEquals(starVertex, starVertex.vertices(Direction.IN, "self").next());
    ///
    assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH)));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT)));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN)));
    vertexIterator = starVertex.vertices(Direction.BOTH);
    assertEquals(starVertex, vertexIterator.next());
    assertEquals(starVertex, vertexIterator.next());
    assertFalse(vertexIterator.hasNext());
    assertEquals(starVertex, starVertex.vertices(Direction.OUT).next());
    assertEquals(starVertex, starVertex.vertices(Direction.IN).next());
    ///
    assertEquals(2l, IteratorUtils.count(starVertex.edges(Direction.BOTH, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.OUT, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.IN, "self", "nothing")));
    Iterator<Edge> edgeIterator = starVertex.edges(Direction.BOTH, "self", "nothing");
    Edge tempEdge = edgeIterator.next();
    assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
    assertEquals("private", tempEdge.value("acl"));
    assertEquals(starEdge, tempEdge);
    tempEdge = edgeIterator.next();
    assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
    assertEquals("private", tempEdge.value("acl"));
    assertEquals(starEdge, tempEdge);
    assertFalse(edgeIterator.hasNext());
    assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next());
    assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next());
    //
    final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0();
    TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);
    TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true);
    TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true);
    // test native non-clone-based methods
    final StarGraph starGraphNative = StarGraph.open();
    Vertex v1 = starGraphNative.addVertex(T.label, "thing", T.id, "v1");
    assertEquals("v1", v1.id());
    assertEquals("thing", v1.label());
    Edge e1 = v1.addEdge("self", v1, "name", "pipes");
    assertEquals(2l, IteratorUtils.count(v1.vertices(Direction.BOTH, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.OUT)));
    assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.IN, "self")));
    edgeIterator = v1.edges(Direction.BOTH);
    TestHelper.validateEdgeEquality(e1, edgeIterator.next());
    TestHelper.validateEdgeEquality(e1, edgeIterator.next());
    assertFalse(edgeIterator.hasNext());
    TestHelper.validateEdgeEquality(e1, v1.edges(Direction.OUT, "self", "nothing").next());
    TestHelper.validateEdgeEquality(e1, v1.edges(Direction.IN).next());
}
 
Example 20
Source File: GraphFilter.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an iterator of legal edges incident to the provided vertex.
 * If no edge filter is provided, then all incident edges are returned.
 *
 * @param vertex the vertex whose legal edges are to be access.
 * @return an iterator of edges that are {@link Legal#YES}.
 */
public Iterator<Edge> legalEdges(final Vertex vertex) {
    return null == this.edgeFilter ?
            vertex.edges(Direction.BOTH) :
            TraversalUtil.applyAll(vertex, this.edgeFilter);
}