<commit_before>package uk.ac.ebi.quickgo.rest.search.results;

import com.google.common.base.Preconditions;
import java.util.*;

/**
 * Contains the all the information pertaining to a search result submitted to a data source.
 */
public class QueryResult<T> {
    private final long numberOfHits;
    private final List<T> results;
    private final PageInfo pageInfo;
    private final Facet facet;
    private final List<DocHighlight> highlighting;

    private QueryResult(long numberOfHits, List<T> results, PageInfo pageInfo, Facet facet,
            List<DocHighlight> highlighting) {
        Preconditions.checkArgument(numberOfHits >= 0, "Total number of hits can not be negative: " + numberOfHits);
        Preconditions.checkArgument(results != null, "Results list can not be null");
        Preconditions.checkArgument(results.size() <= numberOfHits,
                "Total number of results is less than number of results in list: [total: " + numberOfHits + ", " +
                        "results: " + results.size() + "]");

        this.numberOfHits = numberOfHits;
        this.results = Collections.unmodifiableList(results);
        this.pageInfo = pageInfo;
        this.facet = facet;
        this.highlighting = (highlighting != null) ?
                Collections.unmodifiableList(highlighting) : null;
    }

    public List<DocHighlight> getHighlighting() {
        return highlighting;
    }

    public long getNumberOfHits() {
        return numberOfHits;
    }

    public List<T> getResults() {
        return results;
    }

    public PageInfo getPageInfo() {
        return pageInfo;
    }

    public Facet getFacet() {
        return facet;
    }

    @Override public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        QueryResult<?> that = (QueryResult<?>) o;

        if (numberOfHits != that.numberOfHits) {
            return false;
        }
        if (results != null ? !results.equals(that.results) : that.results != null) {
            return false;
        }
        if (pageInfo != null ? !pageInfo.equals(that.pageInfo) : that.pageInfo != null) {
            return false;
        }
        if (facet != null ? !facet.equals(that.facet) : that.facet != null) {
            return false;
        }
        return highlighting != null ? highlighting.equals(that.highlighting) : that.highlighting == null;

    }

    @Override public int hashCode() {
        int result = (int) (numberOfHits ^ (numberOfHits >>> 32));
        result = 31 * result + (results != null ? results.hashCode() : 0);
        result = 31 * result + (pageInfo != null ? pageInfo.hashCode() : 0);
        result = 31 * result + (facet != null ? facet.hashCode() : 0);
        result = 31 * result + (highlighting != null ? highlighting.hashCode() : 0);
        return result;
    }

    @Override public String toString() {
        return "QueryResult{" +
                "numberOfHits=" + numberOfHits +
                ", results=" + results +
                ", pageInfo=" + pageInfo +
                ", facet=" + facet +
                ", highlighting=" + highlighting +
                '}';
    }

    /**
     * Builder used to facilitate the creation of {@link QueryResult} instances.
     *
     * @author <NAME>
     */
    public static class Builder<T> {
        private final long numberOfHits;
        private final List<T> results;

        private PageInfo pageInfo;
        private Facet facets;
        private Set<DocHighlight> highlights;

        public Builder(long hits, List<T> results) {
            this.numberOfHits = hits;
            this.results = results;

            this.highlights = new LinkedHashSet<>();
        }

        public Builder<T> withPageInfo(PageInfo pageInfo) {
            this.pageInfo = pageInfo;
            return this;
        }

        public Builder<T> withFacets(Facet facets) {
            this.facets = facets;
            return this;
        }

        public Builder<T> appendHighlights(DocHighlight... highlight) {
            if (highlight != null) {
                highlights.addAll(Arrays.asList(highlight));
            }
            return this;
        }

        public Builder<T> appendHighlights(Collection<DocHighlight> highlightCol) {
            if (highlightCol != null) {
                highlights.addAll(highlightCol);
            }
            return this;
        }

        public QueryResult<T> build() {
            return new QueryResult<>(numberOfHits, results, pageInfo, facets, new ArrayList<>(highlights));
        }
    }
}<commit_msg>Add aggregation data-structure to the QueryResult.<commit_after>package uk.ac.ebi.quickgo.rest.search.results;

import com.google.common.base.Preconditions;
import java.util.*;

/**
 * Contains the all the information pertaining to a search result submitted to a data source.
 */
public class QueryResult<T> {
    private final long numberOfHits;
    private final List<T> results;
    private final PageInfo pageInfo;
    private final Facet facet;
    private final List<DocHighlight> highlighting;
    private final List<Aggregation> aggregations;

    private QueryResult(long numberOfHits, List<T> results, PageInfo pageInfo, Facet facet,
            List<DocHighlight> highlighting, List<Aggregation> aggregations) {
        Preconditions.checkArgument(numberOfHits >= 0, "Total number of hits can not be negative: " + numberOfHits);
        Preconditions.checkArgument(results != null, "Results list can not be null");
        Preconditions.checkArgument(results.size() <= numberOfHits,
                "Total number of results is less than number of results in list: [total: " + numberOfHits + ", " +
                        "results: " + results.size() + "]");

        this.numberOfHits = numberOfHits;
        this.results = Collections.unmodifiableList(results);
        this.pageInfo = pageInfo;
        this.facet = facet;

        this.highlighting = (highlighting != null) ?
                Collections.unmodifiableList(highlighting) : null;

        this.aggregations = (aggregations != null) ?
                Collections.unmodifiableList(aggregations) : null;
    }

    /**
     * Returns an unmodifiable list of highlights.
     *
     * @return list of highlights
     */
    public List<DocHighlight> getHighlighting() {
        return Collections.unmodifiableList(highlighting);
    }

    public long getNumberOfHits() {
        return numberOfHits;
    }

    public List<T> getResults() {
        return results;
    }

    public PageInfo getPageInfo() {
        return pageInfo;
    }

    public Facet getFacet() {
        return facet;
    }

    /**
     * Returns an unmodifiable list of aggregations.
     *
     * @return list of aggregation results
     */
    public List<Aggregation> getAggregations() {
        return Collections.unmodifiableList(aggregations);
    }

    @Override public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        QueryResult<?> that = (QueryResult<?>) o;

        if (numberOfHits != that.numberOfHits) {
            return false;
        }
        if (!results.equals(that.results)) {
            return false;
        }
        if (pageInfo != null ? !pageInfo.equals(that.pageInfo) : that.pageInfo != null) {
            return false;
        }
        if (facet != null ? !facet.equals(that.facet) : that.facet != null) {
            return false;
        }
        if (!highlighting.equals(that.highlighting)) {
            return false;
        }
        return aggregations.equals(that.aggregations);
    }

    @Override public int hashCode() {
        int result = (int) (numberOfHits ^ (numberOfHits >>> 32));
        result = 31 * result + results.hashCode();
        result = 31 * result + (pageInfo != null ? pageInfo.hashCode() : 0);
        result = 31 * result + (facet != null ? facet.hashCode() : 0);
        result = 31 * result + highlighting.hashCode();
        result = 31 * result + aggregations.hashCode();
        return result;
    }

    @Override public String toString() {
        return "QueryResult{" +
                "numberOfHits=" + numberOfHits +
                ", results=" + results +
                ", pageInfo=" + pageInfo +
                ", facet=" + facet +
                ", highlighting=" + highlighting +
                ", aggregations=" + aggregations +
                '}';
    }

    /**
     * Builder used to facilitate the creation of {@link QueryResult} instances.
     *
     * @author <NAME>
     */
    public static class Builder<T> {
        private final long numberOfHits;
        private final List<T> results;

        private PageInfo pageInfo;
        private Facet facets;
        private Set<DocHighlight> highlights;
        private Set<Aggregation> aggregations;

        public Builder(long hits, List<T> results) {
            this.numberOfHits = hits;
            this.results = results;

            this.highlights = new LinkedHashSet<>();
            this.aggregations = new LinkedHashSet<>();
        }

        public Builder<T> withPageInfo(PageInfo pageInfo) {
            this.pageInfo = pageInfo;
            return this;
        }

        public Builder<T> withFacets(Facet facets) {
            this.facets = facets;
            return this;
        }

        public Builder<T> appendHighlights(DocHighlight... highlight) {
            if (highlight != null) {
                highlights.addAll(Arrays.asList(highlight));
            }
            return this;
        }

        public Builder<T> appendHighlights(Collection<DocHighlight> highlightCol) {
            if (highlightCol != null) {
                highlights.addAll(highlightCol);
            }
            return this;
        }

        public Builder<T> appendAggregations(Aggregation... aggregation) {
            if (aggregation != null) {
                aggregations.addAll(Arrays.asList(aggregation));
            }
            return this;
        }

        public QueryResult<T> build() {
            return new QueryResult<>(numberOfHits,
                    results,
                    pageInfo,
                    facets,
                    new ArrayList<>(highlights),
                    new ArrayList<>(aggregations));
        }
    }
}
{'fraction_non_alphanumeric': 0.10536343717252548, 'fraction_numerical': 0.002857959416976279, 'mean_word_length': 1.9951497860199714, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1697858', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2744, 'n_words': 724}