@Override public void vertexAdded(final Vertex element) { eventedVertex.set(element); assertEquals("thing", element.label()); assertThat(element.properties("here").hasNext(), is(false)); triggered.set(true); } };
private static Map<String, List<VertexProperty>> indexedVertexProperties(final Vertex v) { final Map<String,List<VertexProperty>> index = new HashMap<>(); v.properties().forEachRemaining(vp -> { if (!index.containsKey(vp.key())) { index.put(vp.key(), new ArrayList<>()); } index.get(vp.key()).add(vp); }); return index; }
public static Map<String, List<VertexProperty>> vertexPropertyMap(final Vertex vertex, final String... propertyKeys) { final Map<String, List<VertexProperty>> propertyMap = new HashMap<>(); vertex.properties(propertyKeys).forEachRemaining(property -> { if (propertyMap.containsKey(property.key())) propertyMap.get(property.key()).add(property); else { final List<VertexProperty> list = new ArrayList<>(); list.add(property); propertyMap.put(property.key(), list); } }); return propertyMap; }
@Override public void vertexAdded(final Vertex element) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals("thing", element.label()); assertThat(element.properties("here").hasNext(), is(false)); triggered.set(true); } };
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(baseVertexProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) return Optional.of(vertexProperty); } return Optional.empty(); }
public static Map<String, List> vertexPropertyValueMap(final Vertex vertex, final String... propertyKeys) { final Map<String, List> valueMap = new HashMap<>(); vertex.properties(propertyKeys).forEachRemaining(property -> { if (valueMap.containsKey(property.key())) valueMap.get(property.key()).add(property.value()); else { final List list = new ArrayList(); list.add(property.value()); valueMap.put(property.key(), list); } }); return valueMap; }
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) return Optional.of(vertexProperty); } } return Optional.empty(); }
@Override public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { return IteratorUtils.<VertexProperty<V>, VertexProperty<V>>map(this.getBaseVertex().properties(propertyKeys), property -> new HadoopVertexProperty<>(property, HadoopVertex.this)); } }
v1.properties(property).forEachRemaining(p -> { if (p.value().equals(value1)) { p.remove();
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) public void shouldOverwriteEarlierKeyValuesWithLaterKeyValuesOnAddVertexIfMultiProperty() { final Vertex v = graph.addVertex("test", "A", "test", "B", "test", "C"); tryCommit(graph, graph -> { assertEquals(3, IteratorUtils.count(v.properties("test"))); assertTrue(IteratorUtils.stream(v.values("test")).anyMatch(t -> t.equals("A"))); assertTrue(IteratorUtils.stream(v.values("test")).anyMatch(t -> t.equals("B"))); assertTrue(IteratorUtils.stream(v.values("test")).anyMatch(t -> t.equals("C"))); }); }
v1.properties(property).forEachRemaining(p -> { if (p.value().equals(value1)) { p.remove();
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldReturnEmptyIteratorIfNoProperties() { final Vertex v = graph.addVertex(); assertEquals(0, IteratorUtils.count(v.properties())); } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES, supported = false) public void shouldOverwriteEarlierKeyValuesWithLaterKeyValuesOnAddVertexIfNoMultiProperty() { final Vertex v = graph.addVertex("test", "A", "test", "B", "test", "C"); tryCommit(graph, graph -> { assertEquals(1, IteratorUtils.count(v.properties("test"))); assertTrue(IteratorUtils.stream(v.values("test")).anyMatch(t -> t.equals("C"))); }); }
@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 = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = VertexFeatures.FEATURE_MULTI_PROPERTIES, supported = false) public void shouldSupportMultiPropertyIfTheSameKeyCanBeAssignedMoreThanOnce() throws Exception { try { final Vertex v = graph.addVertex("name", "stephen", "name", "steve"); if (2 == IteratorUtils.count(v.properties())) fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_MULTI_PROPERTIES)); } catch (Exception ex) { validateException(VertexProperty.Exceptions.multiPropertiesNotSupported(), ex); } }
@Override public void map(final Vertex vertex, final MapEmitter emitter) { assertFalse(vertex.property("v1").isPresent()); assertFalse(vertex.property("v2").isPresent()); assertTrue(vertex.property("v3").isPresent()); assertTrue(vertex.property("name").isPresent()); assertEquals(3, IteratorUtils.count(vertex.properties())); assertEquals(3, IteratorUtils.count(vertex.values())); }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY) public void g_V_properties_drop() { final Traversal<Vertex, VertexProperty> traversal = get_g_V_properties_drop(); printTraversalForm(traversal); assertFalse(traversal.hasNext()); assertEquals(6, IteratorUtils.count(g.V())); assertEquals(6, IteratorUtils.count(g.E())); g.V().forEachRemaining(vertex -> assertEquals(0, IteratorUtils.count(vertex.properties()))); }
public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) { final Vertex baseVertex = attachableVertex.get(); final Vertex vertex = hostGraph.features().vertex().willAllowId(baseVertex.id()) ? hostGraph.addVertex(T.id, baseVertex.id(), T.label, baseVertex.label()) : hostGraph.addVertex(T.label, baseVertex.label()); baseVertex.properties().forEachRemaining(vp -> { final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(vp.id()) ? vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value(), T.id, vp.id()) : vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value()); vp.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); }); return vertex; }
@Test @LoadGraphWith(MODERN) @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 g_addVXpersonX_propertyXname_stephenX() { final Traversal<Vertex, Vertex> traversal = get_g_addVXpersonX_propertyXname_stephenX(); printTraversalForm(traversal); final Vertex stephen = traversal.next(); assertFalse(traversal.hasNext()); assertEquals("person", stephen.label()); assertEquals("stephen", stephen.value("name")); assertEquals(1, IteratorUtils.count(stephen.properties())); assertEquals(7, IteratorUtils.count(g.V())); }
@Test @LoadGraphWith(MODERN) @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 g_addVXpersonX_propertyXsingle_name_stephenX_propertyXsingle_name_stephenmX() { final Traversal<Vertex, Vertex> traversal = get_g_addVXpersonX_propertyXsingle_name_stephenX_propertyXsingle_name_stephenmX(); printTraversalForm(traversal); final Vertex stephen = traversal.next(); assertFalse(traversal.hasNext()); assertEquals("person", stephen.label()); assertEquals("stephenm", stephen.value("name")); assertEquals(1, IteratorUtils.count(stephen.properties())); assertEquals(7, IteratorUtils.count(g.V())); }