private Set<String> resolveDocumentTypes(Collection<String> sources, Collection<String> restrict,
                                             Set<String> candidateDocumentTypes) {
        sources = emptyCollectionIfNull(sources);
        restrict = emptyCollectionIfNull(restrict);

        if (sources.isEmpty()) {
            if ( ! restrict.isEmpty()) {
                return new TreeSet<>(restrict);
            } else {
                return candidateDocumentTypes;
            }
        }

        Set<String> toSearch = new TreeSet<>();
        for (String source : sources) { // source: a document type or a cluster containing them
            List<String> clusterDocTypes = clusters.get(source);
            if (clusterDocTypes == null) { // source was a document type
                if (candidateDocumentTypes.contains(source)) {
                    toSearch.add(source);
                }
            } else { // source was a cluster, having document types
                for (String documentType : clusterDocTypes) {
                    if (candidateDocumentTypes.contains(documentType)) {
                        toSearch.add(documentType);
                    }
                }
            }
        }

        if ( ! restrict.isEmpty()) {
            toSearch.retainAll(restrict);
        }

        return toSearch;
    }
Given a search list which is a mixture of document types and cluster
names, and a restrict list which is a list of document types, return a
set of all valid document types for this combination. Most use-cases for
fetching index settings will involve calling this method with the the
incoming query's {@link com.yahoo.search.query.Model#getSources()} and
{@link com.yahoo.search.query.Model#getRestrict()} as input parameters
before calling any other method of this class.

@param sources the search list for a query
@param restrict the restrict list for a query
@return a (possibly empty) set of valid document types
container-search/src/main/java/com/yahoo/prelude/IndexFacts.java