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

org.vertexium.cypher.functions.aggregate.PercentileDiscFunction Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.functions.aggregate;

import org.vertexium.cypher.VertexiumCypherQueryContext;

import java.util.List;

public class PercentileDiscFunction extends PercentileFunction {
    @Override
    protected Object invoke(VertexiumCypherQueryContext ctx, List values, double percentile) {
        int count = values.size();
        values.sort(Double::compare);

        if (percentile == 1.0 || count == 1) {
            return values.get(values.size() - 1);
        } else if (count > 1) {
            double doubleIndex = percentile * (double) count;
            int index = (int) doubleIndex;
            index = (doubleIndex != index || index == 0) ? index : index - 1;
            return values.get(index);
        } else {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy