

package ezbake.data.elastic.common.pojo;

import org.apache.thrift.TException;

import ezbake.data.elastic.thrift.StatisticalFacetResult;

public final class StatisticalFacetResultPojo {
    private long count;
    private double max;
    private double mean;
    private double min;
    private double stdDeviation;
    private double sumOfSquares;
    private double total;
    private double variance;

    public static StatisticalFacetResultPojo fromThrift(StatisticalFacetResult thrift) {
        if (thrift == null) {
            return null;
        }

        final StatisticalFacetResultPojo pojo = new StatisticalFacetResultPojo();
        pojo.count = thrift.getCount();
        pojo.max = thrift.getMax();
        pojo.mean = thrift.getMean();
        pojo.min = thrift.getMin();
        pojo.stdDeviation = thrift.getStdDeviation();
        pojo.sumOfSquares = thrift.getSumOfSquares();
        pojo.total = thrift.getTotal();
        pojo.variance = thrift.getVariance();

        return pojo;
    }

    public static StatisticalFacetResult toThrift(StatisticalFacetResultPojo pojo) throws TException {
        if (pojo == null) {
            return null;
        }

        final StatisticalFacetResult thrift = new StatisticalFacetResult(
                pojo.count, pojo.max, pojo.mean, pojo.min, pojo.stdDeviation, pojo.sumOfSquares, pojo.total,
                pojo.variance);

        thrift.validate();

        return thrift;
    }
}