@@ -0,0 +1,2836 @@
+package uk.ac.ebi.quickgo.rest.search.results;%0A%0Aimport uk.ac.ebi.quickgo.rest.search.AggregateFunction;%0A%0Aimport com.google.common.base.Preconditions;%0Aimport java.util.LinkedHashSet;%0Aimport java.util.Set;%0A%0A/**%0A * Builder for %7B@link AggregateResponse%7D%0A */%0A%0Apublic class AggregateResponseBuilder %7B%0A    private String name;%0A    private AggregationResultsManager aggregationResultsManager;%0A    private final Set%3CAggregateResponse%3E nestedAggregations;%0A    private final Set%3CAggregationBucket%3E buckets;%0A    private int distinctValuesCount;%0A%0A    public AggregateResponseBuilder(String name) %7B%0A        Preconditions.checkArgument(name != null && !name.trim().isEmpty(), %22Name cannot be null or empty%22);%0A%0A        this.name = name;%0A        this.aggregationResultsManager = new AggregationResultsManager();%0A        nestedAggregations = new LinkedHashSet%3C%3E();%0A        buckets = new LinkedHashSet%3C%3E();%0A    %7D%0A%0A    /**%0A     * Adds the result of the application of an aggregation function over a given field.%0A     *%0A     * @param function the aggregation function that was applied%0A     * @param field the field the function was applied over%0A     * @param result the result of the application of the function over the field%0A     */%0A    public void addAggregationResult(AggregateFunction function, String field, double result) %7B%0A        aggregationResultsManager.addAggregateResult(function, field, result);%0A    %7D%0A%0A    /**%0A     * Adds a set of distinct values of a given field. The bucket can also potentially contain aggregation%0A     * results.%0A     *%0A     * @param bucket a set of distinct results of field%0A     */%0A    public void addBucket(AggregationBucket bucket) %7B%0A        Preconditions.checkArgument(bucket != null, %22AggregationBucket cannot be null%22);%0A        buckets.add(bucket);%0A    %7D%0A%0A    /**%0A     * Adds a lower level aggregation to the current one. Usually nested aggregations are drilled down results%0A     * applied to a different field than the current aggregation.%0A     *%0A     * @param aggregation an aggregation%0A     */%0A    public void addNestedAggregation(AggregateResponse aggregation) %7B%0A        Preconditions.checkArgument(aggregation != null, %22Nested aggregation cannot be null%22);%0A        nestedAggregations.add(aggregation);%0A    %7D%0A%0A    /**%0A     * Set the total number of distinct values for the aggregation.%0A     * @param distinctValuesCount calculated number of values of that type%0A     */%0A    public void setDistinctValuesCount(int distinctValuesCount) %7B%0A        this.distinctValuesCount = distinctValuesCount;%0A    %7D%0A%0A    /**%0A     * Create an %7B@link AggregateResponse%7D instance from this class%0A     * @return AggregateResponse instance.%0A     */%0A    public AggregateResponse createAggregateResponse() %7B%0A        return new AggregateResponse(name, aggregationResultsManager, nestedAggregations, buckets, distinctValuesCount);%0A    %7D%0A%7D%0A

Use AggregateResponseBuilder to create AggregateResponse instance.