class MetricUtils {

    protected static boolean applyMetricConstraints(ConstraintEvaluator evaluator, Metric metric, String statistic)
    {
        if (!evaluator.apply(NAMESPACE_FIELD, metric.getNamespace())) {
            return false;
        }

        if (!evaluator.apply(METRIC_NAME_FIELD, metric.getMetricName())) {
            return false;
        }

        if (statistic != null && !evaluator.apply(STATISTIC_FIELD, statistic)) {
            return false;
        }

        for (Dimension next : metric.getDimensions()) {
            if (evaluator.apply(DIMENSION_NAME_FIELD, next.getName()) && evaluator.apply(DIMENSION_VALUE_FIELD, next.getValue())) {
                return true;
            }
        }

        if (metric.getDimensions().isEmpty() &&
                evaluator.apply(DIMENSION_NAME_FIELD, null) &&
                evaluator.apply(DIMENSION_VALUE_FIELD, null)) {
            return true;
        }

        return false;
    }

    private  MetricUtils();

}