<commit_before>package com.vdurmont.semver4j;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.vdurmont.semver4j.Semver.SemverType;
import com.vdurmont.semver4j.Tokenizer.Token;
import com.vdurmont.semver4j.Tokenizer.TokenType;

/**
 * A requirement will provide an easy way to check if a version is satisfying.
 * There are 2 types of requirements:
 * - Strict: checks if a version is equivalent to another
 * - NPM: follows the rules of NPM
 */
public class Requirement {
    private static final Pattern IVY_DYNAMIC_PATCH_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.\\+");
    private static final Pattern IVY_DYNAMIC_MINOR_PATTERN = Pattern.compile("(\\d+)\\.\\+");
    private static final Pattern IVY_LATEST_PATTERN = Pattern.compile("latest\\.\\w+");
    private static final Pattern IVY_MATH_BOUNDED_PATTERN = Pattern.compile(
            "(\\[|\\])" + // 1ST GROUP: a square bracket
                    "([\\d\\.]+)" + // 2ND GROUP: a version
                    "," + // a comma separator
                    "([\\d\\.]+)" + // 3RD GROUP: a version
                    "(\\[|\\])"  // 4TH GROUP: a square bracket
    );
    private static final Pattern IVY_MATH_LOWER_UNBOUNDED_PATTERN = Pattern.compile(
            "\\(," + // a parenthesis and a comma separator
                    "([\\d\\.]+)" + // 1ST GROUP: a version
                    "(\\[|\\])"  // 2ND GROUP: a square bracket
    );
    private static final Pattern IVY_MATH_UPPER_UNBOUNDED_PATTERN = Pattern.compile(
            "(\\[|\\])" + // 1ST GROUP: a square bracket
                    "([\\d\\.]+)" + // 2ND GROUP: a version
                    ",\\)" // a comma separator and a parenthesis
    );

    protected final Range range;
    protected final Requirement req1;
    protected final RequirementOperator op;
    protected final Requirement req2;

    /**
     * Builds a requirement. (private use only)
     *
     * A requirement has to be a range or a combination of an operator and 2 other requirements.
     */
    protected Requirement(Range range, Requirement req1, RequirementOperator op, Requirement req2) {
        this.range = range;
        this.req1 = req1;
        this.op = op;
        this.req2 = req2;
    }

    /**
     * Builds a requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement build(Semver requirement) {
        return new Requirement(new Range(requirement, Range.RangeOperator.EQ), null, null, null);
    }

    /**
     * Builds a strict requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement buildStrict(String requirement) {
        return build(new Semver(requirement));
    }

    /**
     * Builds a loose requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement buildLoose(String requirement) {
        return build(new Semver(requirement, Semver.SemverType.LOOSE));
    }

    /**
     * Builds a requirement following the rules of NPM.
     *
     * @param requirement the requirement as a string
     *
     * @return the generated requirement
     */
    public static Requirement buildNPM(String requirement) {
        if (requirement.isEmpty()) {
            requirement = "*";
        }
        return buildWithTokenizer(requirement, Semver.SemverType.NPM);
    }

    /**
     * Builds a requirement following the rules of Cocoapods.
     *<commit_msg>Requirement: Be explicit about the type in buildStrict()<commit_after>package com.vdurmont.semver4j;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.vdurmont.semver4j.Semver.SemverType;
import com.vdurmont.semver4j.Tokenizer.Token;
import com.vdurmont.semver4j.Tokenizer.TokenType;

/**
 * A requirement will provide an easy way to check if a version is satisfying.
 * There are 2 types of requirements:
 * - Strict: checks if a version is equivalent to another
 * - NPM: follows the rules of NPM
 */
public class Requirement {
    private static final Pattern IVY_DYNAMIC_PATCH_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.\\+");
    private static final Pattern IVY_DYNAMIC_MINOR_PATTERN = Pattern.compile("(\\d+)\\.\\+");
    private static final Pattern IVY_LATEST_PATTERN = Pattern.compile("latest\\.\\w+");
    private static final Pattern IVY_MATH_BOUNDED_PATTERN = Pattern.compile(
            "(\\[|\\])" + // 1ST GROUP: a square bracket
                    "([\\d\\.]+)" + // 2ND GROUP: a version
                    "," + // a comma separator
                    "([\\d\\.]+)" + // 3RD GROUP: a version
                    "(\\[|\\])"  // 4TH GROUP: a square bracket
    );
    private static final Pattern IVY_MATH_LOWER_UNBOUNDED_PATTERN = Pattern.compile(
            "\\(," + // a parenthesis and a comma separator
                    "([\\d\\.]+)" + // 1ST GROUP: a version
                    "(\\[|\\])"  // 2ND GROUP: a square bracket
    );
    private static final Pattern IVY_MATH_UPPER_UNBOUNDED_PATTERN = Pattern.compile(
            "(\\[|\\])" + // 1ST GROUP: a square bracket
                    "([\\d\\.]+)" + // 2ND GROUP: a version
                    ",\\)" // a comma separator and a parenthesis
    );

    protected final Range range;
    protected final Requirement req1;
    protected final RequirementOperator op;
    protected final Requirement req2;

    /**
     * Builds a requirement. (private use only)
     *
     * A requirement has to be a range or a combination of an operator and 2 other requirements.
     */
    protected Requirement(Range range, Requirement req1, RequirementOperator op, Requirement req2) {
        this.range = range;
        this.req1 = req1;
        this.op = op;
        this.req2 = req2;
    }

    /**
     * Builds a requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement build(Semver requirement) {
        return new Requirement(new Range(requirement, Range.RangeOperator.EQ), null, null, null);
    }

    /**
     * Builds a strict requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement buildStrict(String requirement) {
        return build(new Semver(requirement, Semver.SemverType.STRICT));
    }

    /**
     * Builds a loose requirement (will test that the version is equivalent to the requirement)
     *
     * @param requirement the version of the requirement
     *
     * @return the generated requirement
     */
    public static Requirement buildLoose(String requirement) {
        return build(new Semver(requirement, Semver.SemverType.LOOSE));
    }

    /**
     * Builds a requirement following the rules of NPM.
     *
     * @param requirement the requirement as a string
     *
     * @return the generated requirement
     */
    public static Requirement buildNPM(String requirement) {
        if (requirement.isEmpty()) {
            requirement = "*";
        }
        return buildWithTokenizer(requirement, Semver.SemverType.NPM);
    }

    /**
     * Builds a requirement following the rules of Cocoapods.
     *
{'fraction_non_alphanumeric': 0.10920356266942043, 'fraction_numerical': 0.0056796179166128825, 'mean_word_length': 2.3410952996981456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5446269', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2136, 'n_words': 690}