All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.execution.batched.ChildDataCollector Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.execution.batched;

import graphql.schema.GraphQLObjectType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChildDataCollector {

    private final Map> childDataByTypename = new HashMap>();
    private final Map childTypesByName = new HashMap();


    public void putChildData(GraphQLObjectType objectType, GraphQLExecutionNodeDatum datum) {
        childTypesByName.put(objectType.getName(), objectType);
        multimapPut(childDataByTypename, objectType.getName(), datum);
    }

    private  void multimapPut(Map> map, K key, V value) {
        multimapEnsureKey(map, key);
        map.get(key).add(value);
    }

    private  void multimapEnsureKey(Map> map, K key) {
        if (!map.containsKey(key)) {
            map.put(key, new ArrayList());
        }
    }

    private  List multimapGet(Map> map, K key) {
        multimapEnsureKey(map, key);
        return map.get(key);
    }

    public List getEntries() {
        List entries = new ArrayList();
        for (String childTypename : childTypesByName.keySet()) {
            GraphQLObjectType childType = childTypesByName.get(childTypename);
            List childData = multimapGet(childDataByTypename, childTypename);
            entries.add(new Entry(childType, childData));
        }
        return entries;
    }

    public static class Entry {
        private final GraphQLObjectType objectType;
        private final List data;

        public Entry(GraphQLObjectType objectType,
                     List data) {
            this.objectType = objectType;
            this.data = data;
        }

        public GraphQLObjectType getObjectType() {
            return objectType;
        }

        public List getData() {
            return data;
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy