<commit_before>/*
 * Copyright 2011-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kstenschke.shifter.models.shiftertypes;

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

/**
 * Ternary Expression
 */
public class WordsTupel {

    private String delimiter;

    /**
     * Check whether shifted string is a ternary expression
     *
     * @param  str
     * @return boolean
     */
    public boolean isWordsTupel(String str) {
        String glues[] = new String[]{
            ".",
            ",",
            ":",
            "/",
            "*",
            "+",
            "-",
            "%",
            "<", "<=",
            ">", ">=",
            "=", "==", "===", "!=", "!==",
            "&", "&&",
            "|", "||",

            // Space must be last to not be prematurely detected around other delimiter
            " ",
        };

        for (String glue : glues) {
            String delimiterPattern = Pattern.quote(glue);

            if (str.split("\\s*" + delimiterPattern + "\\s*").length == 2) {
                this.delimiter = glue;
                return true;
            }
        }

        return false;
    }

    /**
     * Shift: swap tupel parts
     *
     * @param  str      string to be shifted
     * @return String   The shifted string<commit_msg>improved tupel delimiter pattern order<commit_after>/*
 * Copyright 2011-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kstenschke.shifter.models.shiftertypes;

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

/**
 * Ternary Expression
 */
public class WordsTupel {

    private String delimiter;

    /**
     * Check whether shifted string is a ternary expression
     *
     * @param  str
     * @return boolean
     */
    public boolean isWordsTupel(String str) {
        String glues[] = new String[]{
                // Multi-character delimiters containing singe-character delimiters must precede those
                "!==", "!=",
                "===", "==",
                "<=", ">=",
                "&&", "||",

                ".", ",", ":",
                "+", "-", "/", "*", "%",
                "<", ">", "=",
                "&", "|",

                // Space must be last to not be prematurely detected around other delimiter
                " ",
        };

        for (String glue : glues) {
            String delimiterPattern = Pattern.quote(glue);

            if (str.split("\\s*" + delimiterPattern + "\\s*").length == 2) {
                this.delimiter = glue;
                return true;
            }
        }

        return false;
    }

    /**
     * Shift: swap tupel parts
     *
     * @param  str      string to be shifted
     * @return String   The shifted string
{'fraction_non_alphanumeric': 0.12542639727105748, 'fraction_numerical': 0.006822356336919444, 'mean_word_length': 1.8683220466516177, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4043205', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1013, 'n_words': 333}