本文整理了Java中org.apache.tinkerpop.gremlin.structure.Vertex.keys()
方法的一些代码示例,展示了Vertex.keys()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.keys()
方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Vertex
类名称:Vertex
方法名:keys
暂无
代码示例来源:origin: apache/tinkerpop
@Override
public Set<String> keys() {
if (null == this.properties) return Collections.emptySet();
return TinkerHelper.inComputerMode((TinkerGraph) graph()) ?
Vertex.super.keys() :
this.properties.keySet();
}
代码示例来源:origin: apache/tinkerpop
private static Map<String, String> determineVertexTypes(final Graph graph) {
final Map<String, String> vertexKeyTypes = new HashMap<>();
final Iterator<Vertex> vertices = graph.vertices();
while (vertices.hasNext()) {
final Vertex vertex = vertices.next();
for (String key : vertex.keys()) {
if (!vertexKeyTypes.containsKey(key)) {
vertexKeyTypes.put(key, GraphMLWriter.getStringType(vertex.property(key).value()));
}
}
}
return vertexKeyTypes;
}
代码示例来源:origin: apache/tinkerpop
private static void vertexPropertyChecks(final Vertex v) {
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains(VertexProgramR.PROPERTY_IN));
assertTrue(v.keys().contains(VertexProgramR.PROPERTY_OUT));
assertEquals(1, IteratorUtils.count(v.values(VertexProgramR.PROPERTY_IN)));
assertEquals(1, IteratorUtils.count(v.values(VertexProgramR.PROPERTY_OUT)));
}
代码示例来源:origin: apache/tinkerpop
private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator) throws IOException {
if (vertex.keys().size() == 0)
return;
jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
jsonGenerator.writeStartObject();
final List<String> keys = normalize ?
IteratorUtils.list(vertex.keys().iterator(), Comparator.naturalOrder()) : new ArrayList<>(vertex.keys());
for (String key : keys) {
final Iterator<VertexProperty<Object>> vertexProperties = normalize ?
IteratorUtils.list(vertex.properties(key), Comparators.PROPERTY_COMPARATOR).iterator() : vertex.properties(key);
if (vertexProperties.hasNext()) {
jsonGenerator.writeFieldName(key);
jsonGenerator.writeStartArray();
while (vertexProperties.hasNext()) {
jsonGenerator.writeObject(vertexProperties.next());
}
jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndObject();
}
}
代码示例来源:origin: apache/tinkerpop
private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator) throws IOException {
if (vertex.keys().size() == 0)
return;
jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
jsonGenerator.writeStartObject();
final List<String> keys = normalize ?
IteratorUtils.list(vertex.keys().iterator(), Comparator.naturalOrder()) : new ArrayList<>(vertex.keys());
for (String key : keys) {
final Iterator<VertexProperty<Object>> vertexProperties = normalize ?
IteratorUtils.list(vertex.properties(key), Comparators.PROPERTY_COMPARATOR).iterator() : vertex.properties(key);
if (vertexProperties.hasNext()) {
jsonGenerator.writeFieldName(key);
jsonGenerator.writeStartArray();
while (vertexProperties.hasNext()) {
jsonGenerator.writeObject(vertexProperties.next());
}
jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndObject();
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY)
public void shouldGetPropertyKeysOnVertex() {
final Vertex v = graph.addVertex("name", "marko", "location", "desert", "status", "dope");
Set<String> keys = v.keys();
assertEquals(3, keys.size());
assertTrue(keys.contains("name"));
assertTrue(keys.contains("location"));
assertTrue(keys.contains("status"));
final List<VertexProperty<Object>> m = IteratorUtils.list(v.properties());
assertEquals(3, m.size());
assertTrue(m.stream().anyMatch(p -> p.key().equals("name")));
assertTrue(m.stream().anyMatch(p -> p.key().equals("location")));
assertTrue(m.stream().anyMatch(p -> p.key().equals("status")));
assertEquals("marko", m.stream().filter(p -> p.key().equals("name")).map(Property::value).findAny().orElse(null));
assertEquals("desert", m.stream().filter(p -> p.key().equals("location")).map(Property::value).findAny().orElse(null));
assertEquals("dope", m.stream().filter(p -> p.key().equals("status")).map(Property::value).findAny().orElse(null));
v.property("status").remove();
keys = v.keys();
assertEquals(2, keys.size());
assertTrue(keys.contains("name"));
assertTrue(keys.contains("location"));
v.properties().forEachRemaining(Property::remove);
keys = v.keys();
assertEquals(0, keys.size());
}
代码示例来源:origin: apache/tinkerpop
private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
final List<String> keys = normalize ?
IteratorUtils.list(vertex.keys().iterator(), Comparator.naturalOrder()) : new ArrayList<>(vertex.keys());
for (String key : keys) {
final Iterator<VertexProperty<Object>> vertexProperties = normalize ?
IteratorUtils.list(vertex.properties(key), Comparators.PROPERTY_COMPARATOR).iterator() : vertex.properties(key);
if (vertexProperties.hasNext()) {
jsonGenerator.writeArrayFieldStart(key);
if (typeSerializer != null) {
jsonGenerator.writeString(ArrayList.class.getName());
jsonGenerator.writeStartArray();
}
while (vertexProperties.hasNext()) {
serializerVertexProperty(vertexProperties.next(), jsonGenerator, serializerProvider, typeSerializer, normalize, false);
}
jsonGenerator.writeEndArray();
if (typeSerializer != null) jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndObject();
}
代码示例来源:origin: apache/tinkerpop
public static void validateVertexEquality(final Vertex originalVertex, final Vertex otherVertex, boolean testEdges) {
assertEquals(originalVertex, otherVertex);
assertEquals(otherVertex, originalVertex);
assertEquals(originalVertex.id(), otherVertex.id());
assertEquals(originalVertex.label(), otherVertex.label());
assertEquals(originalVertex.keys().size(), otherVertex.keys().size());
for (final String key : originalVertex.keys()) {
final List<VertexProperty<Object>> originalVertexProperties = IteratorUtils.list(originalVertex.properties(key));
final List<VertexProperty<Object>> otherVertexProperties = IteratorUtils.list(otherVertex.properties(key));
assertEquals(originalVertexProperties.size(), otherVertexProperties.size());
for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) {
final VertexProperty<Object> otherVertexProperty = otherVertexProperties.parallelStream().filter(vp -> vp.equals(originalVertexProperty)).findAny().get();
validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty);
}
}
if (testEdges) {
Iterator<Edge> originalEdges = IteratorUtils.list(originalVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR).iterator();
Iterator<Edge> otherEdges = IteratorUtils.list(otherVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR).iterator();
while (originalEdges.hasNext()) {
validateEdgeEquality(originalEdges.next(), otherEdges.next());
}
assertFalse(otherEdges.hasNext());
originalEdges = IteratorUtils.list(originalVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR).iterator();
otherEdges = IteratorUtils.list(otherVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR).iterator();
while (originalEdges.hasNext()) {
validateEdgeEquality(originalEdges.next(), otherEdges.next());
}
assertFalse(otherEdges.hasNext());
}
}
代码示例来源:origin: apache/tinkerpop
assertEquals("marko", v.<String>property("name").value());
assertEquals(2, IteratorUtils.count(v.properties()));
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains("age"));
assertFalse(v.keys().contains("location"));
assertVertexEdgeCounts(graph, 1, 0);
assertEquals("marko rodriguez", v.<String>property("name").value());
assertEquals(2, IteratorUtils.count(v.properties()));
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains("age"));
assertFalse(v.keys().contains("location"));
assertVertexEdgeCounts(graph, 1, 0);
assertEquals(3, v.keys().size());
assertEquals("santa fe", v.property("location").value());
assertEquals(v.property("location"), v.property("location"));
assertNotEquals(v.property("location"), v.property("name"));
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains("age"));
assertTrue(v.keys().contains("location"));
v.property("location").remove();
assertVertexEdgeCounts(graph, 1, 0);
代码示例来源:origin: apache/tinkerpop
program(PageRankVertexProgram.build().epsilon(0.0d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.0, we guarantee iterations 30
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(3, v.keys().size()); // name, age/lang, pageRank
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
assertEquals(1, IteratorUtils.count(v.values("name")));
assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
代码示例来源:origin: apache/tinkerpop
program(PageRankVertexProgram.build().epsilon(0.00001d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.00001, we should get iterations 11
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(3, v.keys().size()); // name, age/lang, pageRank
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
assertEquals(1, IteratorUtils.count(v.values("name")));
assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
代码示例来源:origin: apache/tinkerpop
public static void assertNoEdgeGraph(final Graph g1, final boolean assertDouble, final boolean lossyForId) {
assertEquals(2, IteratorUtils.count(g1.vertices()));
assertEquals(1, IteratorUtils.count(g1.edges()));
final Vertex v1 = g1.traversal().V().has("name", "marko").next();
assertEquals(29, v1.<Integer>value("age").intValue());
assertEquals(2, v1.keys().size());
assertEquals(Vertex.DEFAULT_LABEL, v1.label());
assertId(g1, lossyForId, v1, 1);
final List<Edge> v1Edges = IteratorUtils.list(v1.edges(Direction.BOTH));
assertEquals(1, v1Edges.size());
v1Edges.forEach(e -> {
if (e.inVertex().value("name").equals("vadas")) {
assertEquals(Edge.DEFAULT_LABEL, e.label());
if (assertDouble)
assertWeightLoosely(0.5d, e);
else
assertWeightLoosely(0.5f, e);
assertEquals(1, e.keys().size());
assertId(g1, lossyForId, e, 7);
} else {
fail("Edge not expected");
}
});
}
代码示例来源:origin: apache/tinkerpop
assertEquals(2, v1.keys().size());
assertEquals(4, (int) IteratorUtils.count(v1.properties("location")));
v1.properties("location").forEachRemaining(vp -> {
assertEquals(2, v7.keys().size());
assertEquals(3, (int) IteratorUtils.count(v7.properties("location")));
v7.properties("location").forEachRemaining(vp -> {
assertEquals(2, v8.keys().size());
assertEquals(4, (int) IteratorUtils.count(v8.properties("location")));
v8.properties("location").forEachRemaining(vp -> {
assertEquals(2, v9.keys().size());
assertEquals(3, (int) IteratorUtils.count(v9.properties("location")));
v9.properties("location").forEachRemaining(vp -> {
assertEquals(1, v10.keys().size());
assertId(g1, lossyForId, v10, 10);
assertEquals(1, v11.keys().size());
assertId(g1, lossyForId, v11, 11);
代码示例来源:origin: apache/tinkerpop
assertEquals(2, v1.keys().size());
assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v1.label());
assertId(g1, lossyForId, v1, 1);
assertEquals(2, v2.keys().size());
assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v2.label());
assertId(g1, lossyForId, v2, 2);
assertEquals(2, v2.keys().size());
assertEquals(assertSpecificLabel ? "software" : Vertex.DEFAULT_LABEL, v3.label());
assertId(g1, lossyForId, v3, 3);
assertEquals(2, v4.keys().size());
assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v4.label());
assertId(g1, lossyForId, v4, 4);
assertEquals(2, v5.keys().size());
assertEquals(assertSpecificLabel ? "software" : Vertex.DEFAULT_LABEL, v5.label());
assertId(g1, lossyForId, v5, 5);
assertEquals(2, v6.keys().size());
assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v6.label());
assertId(g1, lossyForId, v6, 6);
代码示例来源:origin: apache/tinkerpop
final ComputerResult result = graphProvider.getGraphComputer(graph).program(BulkDumperVertexProgram.build().create(graph)).submit().get();
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains("age") || v.keys().contains("lang"));
assertEquals(1, IteratorUtils.count(v.values("name")));
assertEquals(1, IteratorUtils.count(v.values("age", "lang")));
代码示例来源:origin: apache/tinkerpop
final ComputerResult result = graphProvider.getGraphComputer(graph).program(CloneVertexProgram.build().create(graph)).submit().get();
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains("name"));
assertTrue(v.keys().contains("age") || v.keys().contains("lang"));
assertEquals(1, IteratorUtils.count(v.values("name")));
assertEquals(1, IteratorUtils.count(v.values("age", "lang")));
代码示例来源:origin: org.apache.tinkerpop/tinkergraph-gremlin
@Override
public Set<String> keys() {
if (null == this.properties) return Collections.emptySet();
return TinkerHelper.inComputerMode((TinkerGraph) graph()) ?
Vertex.super.keys() :
this.properties.keySet();
}
代码示例来源:origin: HuygensING/timbuctoo
@Override
public String get(Vertex vertex) {
if (vertex.keys().contains(propertyName)) {
String value = parser.parse(vertex.value(propertyName));
if (value != null) {
return String.format("%s%s%s", prefix, value, postfix);
}
}
return null;
}
}
代码示例来源:origin: io.shiftleft/tinkergraph-gremlin
@Override
public Set<String> keys() {
if (null == this.properties) return Collections.emptySet();
return TinkerHelper.inComputerMode((TinkerGraph) graph()) ?
Vertex.super.keys() :
this.properties.keySet();
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-test
private static void vertexPropertyChecks(final Vertex v) {
assertEquals(2, v.keys().size());
assertTrue(v.keys().contains(VertexProgramR.PROPERTY_IN));
assertTrue(v.keys().contains(VertexProgramR.PROPERTY_OUT));
assertEquals(1, IteratorUtils.count(v.values(VertexProgramR.PROPERTY_IN)));
assertEquals(1, IteratorUtils.count(v.values(VertexProgramR.PROPERTY_OUT)));
}
内容来源于网络,如有侵权,请联系作者删除!