private GraphView buildGraphView()

in hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/query/GremlinQueryService.java [318:367]


    private GraphView buildGraphView(TypedResult result, HugeClient client) {
        List<Object> data = result.getData();
        if (!result.getType().isGraph() || CollectionUtils.isEmpty(data)) {
            return GraphView.EMPTY;
        }

        Map<Object, Vertex> vertices = new HashMap<>();
        Map<String, Edge> edges = new HashMap<>();
        for (Object object : data) {
            if (object instanceof Vertex) {
                Vertex vertex = (Vertex) object;
                vertices.put(vertex.id(), vertex);
            } else if (object instanceof Edge) {
                Edge edge = (Edge) object;
                edges.put(edge.id(), edge);
            } else if (object instanceof Path) {
                List<Object> elements = ((Path) object).objects();
                for (Object element : elements) {
                    if (element instanceof Vertex) {
                        Vertex vertex = (Vertex) element;
                        vertices.put(vertex.id(), vertex);
                    } else if (element instanceof Edge) {
                        Edge edge = (Edge) element;
                        edges.put(edge.id(), edge);
                    } else {
                        return GraphView.EMPTY;
                    }
                }
            }
        }

        if (!edges.isEmpty()) {
            if (vertices.isEmpty()) {
                vertices = this.verticesOfEdge(result, edges, client);
            } else {
                // TODO: reduce the number of requests
                vertices.putAll(this.verticesOfEdge(result, edges, client));
            }
        } else {
            if (!vertices.isEmpty()) {
                edges = this.edgesOfVertex(result, vertices, client);
            }
        }

        if (!edges.isEmpty()) {
            Ex.check(!vertices.isEmpty(),
                     "gremlin.edges.linked-vertex.not-exist");
        }
        return new GraphView(vertices.values(), edges.values());
    }