private TypedResult parseResults()

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


    private TypedResult parseResults(ResultSet resultSet) {
        if (resultSet == null) {
            return new TypedResult(Type.EMPTY, null);
        }
        Iterator<Result> iter = resultSet.iterator();
        if (!iter.hasNext()) {
            return new TypedResult(Type.EMPTY, null);
        }

        Map<Type, Integer> typeVotes = new HashMap<>();
        List<Object> typedData = new ArrayList<>(resultSet.size());
        while (iter.hasNext()) {
            Result result = iter.next();
            if (result == null) {
                // NOTE: null value doesn't vote
                continue;
            }
            Object object = result.getObject();
            Type type;
            if (object instanceof Vertex) {
                type = Type.VERTEX;
            } else if (object instanceof Edge) {
                type = Type.EDGE;
            } else if (object instanceof Path) {
                type = Type.PATH;
            } else {
                type = Type.GENERAL;
            }
            typeVotes.compute(type, (k, v) -> v == null ? 1 : v + 1);
            typedData.add(object);
        }

        Type type;
        if (typeVotes.isEmpty()) {
            type = Type.EMPTY;
        } else {
            // Find the key with max value
            type = Collections.max(typeVotes.entrySet(),
                                   Comparator.comparingInt(Map.Entry::getValue))
                              .getKey();
        }
        return new TypedResult(type, typedData);
    }