<commit_before>/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package permafrost.tundra.data;

import permafrost.tundra.math.DecimalHelper;
import permafrost.tundra.math.IntegerHelper;
import permafrost.tundra.time.DateTimeHelper;
import permafrost.tundra.time.DurationHelper;

/**
 * Compares two IData objects using the values associated with the given
 * list of keys in precedence order.
 */
public class CriteriaBasedIDataComparator implements IDataComparator {
    protected java.util.List<IDataComparisonCriterion> criteria;

    /**
     * Construct a new IDataComparator with one or more comparison criteria.
     *
     * @param criteria The comparison criteria to be used when comparing IData objects.
     */
    public CriteriaBasedIDataComparator(IDataComparisonCriterion... criteria) {
        this(java.util.Arrays.asList(criteria));
    }

    /**
     * Construct a new IDataComparator with one or more comparison criteria.
     *
     * @param criteria The comparison criteria to be used when comparing IData objects.
     */
    public CriteriaBasedIDataComparator(java.util.List<IDataComparisonCriterion> criteria) {
        if (criteria == null || criteria.size() == 0) throw new IllegalArgumentException("At least one comparison criteria is required to construct an IDataComparator object");
        this.criteria = criteria;
    }

    /**
     * Normalizes the given comparison result for when the comparison should
     * be in descending order.
     *
     * @param result     A comparison result.
     * @param descending Whether the comparison should be in descending order.
     * @return           If descending is true, returns the given comparison
     *                   result negated, otherwise returns the result unchanged.
     */
    protected static int normalize(int result, boolean descending) {
        if (descending) {
            if (result < 0) {
                result = 1;
            } else if (result > 0) {
                result = -1;
            }
        }
        return result;
    }

    /**<commit_msg>Fix exception message in CriteriaBasedIDataComparator constructor to use correct class name<commit_after>/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package permafrost.tundra.data;

import permafrost.tundra.math.DecimalHelper;
import permafrost.tundra.math.IntegerHelper;
import permafrost.tundra.time.DateTimeHelper;
import permafrost.tundra.time.DurationHelper;

import java.util.Arrays;

/**
 * Compares two IData objects using the values associated with the given
 * list of keys in precedence order.
 */
public class CriteriaBasedIDataComparator implements IDataComparator {
    protected java.util.List<IDataComparisonCriterion> criteria;

    /**
     * Construct a new IDataComparator with one or more comparison criteria.
     *
     * @param criteria The comparison criteria to be used when comparing IData objects.
     */
    public CriteriaBasedIDataComparator(IDataComparisonCriterion... criteria) {
        this(Arrays.asList(criteria));
    }

    /**
     * Construct a new IDataComparator with one or more comparison criteria.
     *
     * @param criteria The comparison criteria to be used when comparing IData objects.
     */
    public CriteriaBasedIDataComparator(java.util.List<IDataComparisonCriterion> criteria) {
        if (criteria == null || criteria.size() == 0) throw new IllegalArgumentException("At least one comparison criteria is required to construct an CriteriaBasedIDataComparator object");
        this.criteria = criteria;
    }

    /**
     * Normalizes the given comparison result for when the comparison should
     * be in descending order.
     *
     * @param result     A comparison result.
     * @param descending Whether the comparison should be in descending order.
     * @return           If descending is true, returns the given comparison
     *                   result negated, otherwise returns the result unchanged.
     */
    protected static int normalize(int result, boolean descending) {
        if (descending) {
            if (result < 0) {
                result = 1;
            } else if (result > 0) {
                result = -1;
            }
        }
        return result;
    }

    /**
{'fraction_non_alphanumeric': 0.06654199781829516, 'fraction_numerical': 0.002805049088359046, 'mean_word_length': 3.151358344113842, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3836480', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1557, 'n_words': 702}