本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.addVertex()
方法的一些代码示例,展示了Graph.addVertex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.addVertex()
方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:addVertex
[英]Add a Vertex to the graph with provided vertex label.
[中]使用提供的顶点标签向图形添加顶点。
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldHashAndEqualCorrectly() {
final Vertex v = graph.addVertex();
final Edge e = v.addEdge("test", v);
final Set<Edge> set = new HashSet<>();
for (int i = 0; i < 100; i++) {
set.add(ReferenceFactory.detach(e));
set.add(e);
}
assertEquals(1, set.size());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldHaveStandardStringRepresentationForVertexProperty() {
final Vertex v = graph.addVertex("name", "marko");
final Property p = v.property("name");
assertEquals(StringFactory.propertyString(p), p.toString());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false)
public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "stephen");
if (p.id() instanceof Number)
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_NUMERIC_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_STRING_IDS, supported = false)
public void shouldSupportStringIdsIfStringIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
if (v.id() instanceof String)
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES, supported = false)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldSupportAddEdgesIfEdgeCanBeAdded() throws Exception {
try {
final Vertex v = graph.addVertex();
v.addEdge("friend", v);
fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_ADD_EDGES));
} catch (Exception e) {
validateException(Vertex.Exceptions.edgeAdditionsNotSupported(), e);
}
}
代码示例来源:origin: apache/tinkerpop
@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)
public void shouldEnableFeatureOnVertexIfNotEnabled() throws Exception {
assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(false));
try {
graph.addVertex("aKey", value);
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), featureName));
} catch (Exception e) {
validateException(Property.Exceptions.dataTypeOfPropertyValueNotSupported(value), e);
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldNotBeEqualsPropertiesAsIdIsDifferent() {
final Vertex v = graph.addVertex();
final VertexProperty vp1 = v.property(VertexProperty.Cardinality.single, "test", "this");
final ReferenceVertexProperty mp1 = ReferenceFactory.detach(vp1);
final VertexProperty vp2 = v.property(VertexProperty.Cardinality.single, "testing", "this");
final ReferenceVertexProperty mp2 = ReferenceFactory.detach(vp2);
assertFalse(mp1.equals(mp2));
}
代码示例来源:origin: apache/tinkerpop
@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)
public void shouldSetValueOnVertex() throws Exception {
assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(true));
final Vertex vertex = graph.addVertex();
vertex.property(VertexProperty.Cardinality.single, "aKey", value);
assertPropertyValue(vertex);
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldHaveStandardStringRepresentation() {
final Vertex v1 = graph.addVertex();
final Vertex v2 = graph.addVertex();
final Edge e = v1.addEdge("friends", v2);
assertEquals(StringFactory.edgeString(e), e.toString());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldHaveTruncatedStringRepresentationForVertexProperty() {
final Vertex v = graph.addVertex("name", "maria de la santa cruz rosalina agnelia rodriguez cuellar rene");
final Property p = v.property("name");
assertEquals(StringFactory.propertyString(p), p.toString());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
if (v.id() instanceof UUID)
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_UUID_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false)
public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
final Edge e = v.addEdge("knows", v);
if (e.id() instanceof Number)
fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_NUMERIC_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "stephen");
if (p.id() instanceof UUID)
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_UUID_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldBeEqualsPropertiesAsIdIsTheSame() {
final Vertex v = graph.addVertex();
final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "this");
final ReferenceVertexProperty vp1 = ReferenceFactory.detach(vp);
final ReferenceVertexProperty vp2 = ReferenceFactory.detach(vp);
assertTrue(vp1.equals(vp2));
assertTrue(vp1.equals(vp));
assertTrue(vp.equals(vp2));
}
代码示例来源:origin: apache/tinkerpop
@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_STRING_IDS)
public void shouldIterateVerticesWithStringIdSupportUsingVertices() {
// if the graph supports id assigned, it should allow it. if the graph does not, it will generate one
final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "2") : graph.addVertex();
graph.addVertex();
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldSetLabelOfVertexPropertyToKeyOfOwningProperty() {
final Vertex v = graph.addVertex("name", "stephen");
tryCommit(graph, g -> assertEquals("name", v.property("name").label()));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldHaveExceptionConsistencyWhenUsingNullVertexLabel() {
try {
graph.addVertex(T.label, null);
fail("Call to Graph.addVertex() should throw an exception when label is null");
} catch (Exception ex) {
validateException(Element.Exceptions.labelCanNotBeNull(), ex);
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_STRING_IDS, supported = false)
public void shouldSupportStringIdsIfStringIdsAreGeneratedFromTheGraph() throws Exception {
final Vertex v = graph.addVertex();
final Edge e = v.addEdge("knows", v);
if (e.id() instanceof String)
fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = VertexFeatures.FEATURE_ADD_PROPERTY, supported = false)
public void shouldSupportAddVertexPropertyIfItCanBeAdded() throws Exception {
try {
final Vertex v = graph.addVertex();
v.property(VertexProperty.Cardinality.single, "should", "not-add-property");
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_ADD_PROPERTY));
} catch (Exception e) {
validateException(Element.Exceptions.propertyAdditionNotSupported(), e);
}
}
代码示例来源:origin: apache/tinkerpop
@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_UUID_IDS)
public void shouldIterateVerticesWithUuidIdSupportUsingVertices() {
// if the graph supports id assigned, it should allow it. if the graph does not, it will generate one
final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
graph.addVertex();
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
});
}
内容来源于网络,如有侵权,请联系作者删除!