public Stream<M> receiveMessages(MessageScope messageScope) { if (messageScope instanceof MessageScope.Global) { M message = vertexMemory.getMessage(vertexId,messageScope); if (message == null) return Stream.empty(); else return Stream.of(message); } else { final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope; final BiFunction<M,Edge,M> edgeFct = localMessageScope.getEdgeFunction(); final List<Edge> edges; try (final Traversal<Vertex, Edge> reverseIncident = FulgoraUtil.getReverseElementTraversal(localMessageScope,vertex,vertex.tx())) { edges = IteratorUtils.list(reverseIncident); } catch (Exception e) { throw new JanusGraphException("Unable to close traversal", e); } return edges.stream() .map(e -> { M msg = vertexMemory.getMessage(vertexMemory.getCanonicalId(((JanusGraphEdge) e).otherVertex(vertex).longId()), localMessageScope); return msg == null ? null : edgeFct.apply(msg, e); }) .filter(Objects::nonNull); } }
public static <S> List<S> list(final Iterator<S> iterator, final Comparator comparator) { final List<S> l = list(iterator); Collections.sort(l, comparator); return l; }
private Builder(final Graph g) { super(Builder.class); this.g = g; final List<Vertex> allVertices = IteratorUtils.list(g.vertices()); this.out = allVertices; this.in = allVertices; this.expectedNumEdges = allVertices.size() * 2; }
private Builder(final Graph g) { super(Builder.class); this.g = g; final List<Vertex> allVertices = IteratorUtils.list(g.vertices()); this.vertices = allVertices; this.expectedNumEdges = allVertices.size() * 2; }
public DetachedVertex(final Object id, final String label, final Map<String, Object> properties) { super(id, label); if (properties != null && !properties.isEmpty()) { this.properties = new HashMap<>(); properties.entrySet().iterator().forEachRemaining(entry -> this.properties.put(entry.getKey(), IteratorUtils.<Property>list(IteratorUtils.map(((List<Object>) entry.getValue()).iterator(), m -> VertexProperty.class.isAssignableFrom(m.getClass()) ? (VertexProperty) m : new DetachedVertexProperty<>(((Map) m).get(ID), entry.getKey(), ((Map) m).get(VALUE), (Map<String, Object>) ((Map) m).getOrDefault(PROPERTIES, new HashMap<>()), this))))); } }
public static List asList(final Object o) { return list(asIterator(o)); }
private Iterable<Vertex> getVerticesAndNormalizeIfRequired(final Graph graph) { final Iterable<Vertex> vertices; if (normalize) { vertices = new ArrayList<>(); final Iterator<Vertex> vertexIterator = graph.vertices(); while (vertexIterator.hasNext()) { ((Collection<Vertex>) vertices).add(vertexIterator.next()); } Collections.sort((List<Vertex>) vertices, Comparators.ELEMENT_COMPARATOR); } else vertices = IteratorUtils.list(graph.vertices()); return vertices; }
protected Iterable<Vertex> verticesByOid(final Graph graph) { List<Vertex> vertices = IteratorUtils.list(graph.vertices()); Collections.sort(vertices, (v1, v2) -> ((Integer) v1.value("oid")).compareTo((Integer) v2.value("oid"))); return vertices; }
protected Iterable<Vertex> verticesByOid(final Graph graph) { List<Vertex> vertices = IteratorUtils.list(graph.vertices()); Collections.sort(vertices, (v1, v2) -> ((Integer) v1.value("oid")).compareTo((Integer) v2.value("oid"))); return vertices; }
private <V> Iterator<HugeTask<V>> queryTask(List<Id> ids) { return this.call(() -> { Object[] idArray = ids.toArray(new Id[ids.size()]); Iterator<Vertex> vertices = this.tx().queryVertices(idArray); Iterator<HugeTask<V>> tasks = new MapperIterator<>(vertices, HugeTask::fromVertex); // Convert iterator to list to avoid across thread tx accessed return IteratorUtils.list(tasks); }).iterator(); }
private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator) throws IOException { final Iterator<Property<Object>> elementProperties = normalize ? IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties(); if (elementProperties.hasNext()) { jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES); jsonGenerator.writeStartObject(); elementProperties.forEachRemaining(prop -> safeWriteObjectField(jsonGenerator, prop.key(), prop)); jsonGenerator.writeEndObject(); } } }
private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator) throws IOException { final Iterator<Property<Object>> elementProperties = normalize ? IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties(); if (elementProperties.hasNext()) { jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES); jsonGenerator.writeStartObject(); elementProperties.forEachRemaining(prop -> safeWriteObjectField(jsonGenerator, prop.key(), prop)); jsonGenerator.writeEndObject(); } } }
private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { final Iterator<Property<Object>> elementProperties = normalize ? IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties(); if (elementProperties.hasNext()) { jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); while (elementProperties.hasNext()) { final Property<Object> elementProperty = elementProperties.next(); GraphSONUtil.writeWithType(elementProperty.key(), elementProperty.value(), jsonGenerator, serializerProvider, typeSerializer); } jsonGenerator.writeEndObject(); } }
private static void writeMetaProperties(final VertexProperty property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer, final boolean normalize) throws IOException { jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); final Iterator<Property<Object>> metaProperties = normalize ? IteratorUtils.list(( Iterator<Property<Object>>) property.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : property.properties(); while (metaProperties.hasNext()) { final Property<Object> metaProperty = metaProperties.next(); GraphSONUtil.writeWithType(metaProperty.key(), metaProperty.value(), jsonGenerator, serializerProvider, typeSerializer); } jsonGenerator.writeEndObject(); }
private static void writeMetaProperties(final VertexProperty property, final JsonGenerator jsonGenerator, final boolean normalize) throws IOException { jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES); jsonGenerator.writeStartObject(); final Iterator<Property<Object>> metaProperties = normalize ? IteratorUtils.list((Iterator<Property<Object>>) property.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : property.properties(); while (metaProperties.hasNext()) { final Property<Object> metaProperty = metaProperties.next(); jsonGenerator.writeObjectField(metaProperty.key(), metaProperty.value()); } jsonGenerator.writeEndObject(); } }
private static void writeMetaProperties(final VertexProperty property, final JsonGenerator jsonGenerator, final boolean normalize) throws IOException { jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES); jsonGenerator.writeStartObject(); final Iterator<Property<Object>> metaProperties = normalize ? IteratorUtils.list((Iterator<Property<Object>>) property.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : property.properties(); while (metaProperties.hasNext()) { final Property<Object> metaProperty = metaProperties.next(); jsonGenerator.writeObjectField(metaProperty.key(), metaProperty.value()); } jsonGenerator.writeEndObject(); } }
/** * Asserts that two graphs are the "same" in way of structure. It assumes that the graphs both have vertices * with an "oid" property that is an Integer value. It iterates each vertex in graph 1, using the "oid" to * lookup vertices in graph 2. For each one found it checks both IN and OUT vertices to ensure that they * attach to the same IN/OUT vertices given their "oid" properties. */ protected boolean same(final Graph g1, final Graph g2) { return IteratorUtils.stream(g1.vertices()) .map(v -> Triplet.<Integer, List<Vertex>, List<Vertex>>with(v.value("oid"), IteratorUtils.list(v.vertices(Direction.IN)), IteratorUtils.list(v.vertices(Direction.OUT)))) .allMatch(p -> { final Vertex v = IteratorUtils.filter(g2.vertices(), vx -> vx.value("oid").equals(p.getValue0())).next(); return sameInVertices(v, p.getValue1()) && sameOutVertices(v, p.getValue2()); }); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY) public void shouldAllowIteratingAndRemovingVertexPropertyProperties() { final Vertex daniel = graph.addVertex("name", "daniel", "name", "kuppitz", "name", "big d", "name", "the german"); daniel.properties("name").forEachRemaining(vp -> { vp.<Object>property("aKey", UUID.randomUUID().toString()); vp.<Object>property("bKey", UUID.randomUUID().toString()); vp.<Object>property("cKey", UUID.randomUUID().toString()); }); assertEquals(4, IteratorUtils.count(daniel.properties())); assertEquals(12, IteratorUtils.list(IteratorUtils.map(daniel.properties(), p -> IteratorUtils.count(p.properties()))).stream().mapToInt(kv -> kv.intValue()).sum()); daniel.properties().forEachRemaining(p -> p.properties().forEachRemaining(Property::remove)); assertEquals(4, IteratorUtils.count(daniel.properties())); assertEquals(0, IteratorUtils.list(IteratorUtils.map(daniel.properties(), p -> IteratorUtils.count(p.properties()))).stream().mapToInt(kv -> kv.intValue()).sum()); daniel.properties().forEachRemaining(VertexProperty::remove); assertEquals(0, IteratorUtils.count(daniel.properties())); assertEquals(0, IteratorUtils.list(IteratorUtils.map(daniel.properties(), p -> IteratorUtils.count(p.properties()))).stream().mapToInt(kv -> kv.intValue()).sum()); }
@Test public void testQueryAllWithLimitByQueryEdges() { HugeGraph graph = graph(); init18Edges(); Query query = new Query(HugeType.EDGE); query.limit(1); Iterator<Edge> itor = graph.graphTransaction().queryEdges(query); List<Edge> edges = IteratorUtils.list(itor); Assert.assertEquals(1, edges.size()); }
@Test public void testQueryAllWithLimitByQueryVertices() { HugeGraph graph = graph(); init10Vertices(); Query query = new Query(HugeType.VERTEX); query.limit(1); Iterator<Vertex> itor = graph.graphTransaction().queryVertices(query); List<Vertex> vertices = IteratorUtils.list(itor); Assert.assertEquals(1, vertices.size()); }