<commit_before>package de.factoryfx.javafx.util;

import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.function.Consumer;

import com.google.common.base.Strings;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;

public class TypedTextFieldHelper {

    private static Consumer<String> stringConsumer;

    private static void setupTextField(TextField textField, Consumer<String> converter) {
        textField.setTextFormatter(new TextFormatter<>(change -> {
            try {
                if (!Strings.isNullOrEmpty(change.getControlNewText())) {
                    converter.accept(change.getControlNewText());
                }
                return change;
            } catch (IllegalArgumentException e) { //javafxbug https://bugs.openjdk.java.net/browse/JDK-8081700
                return null;
            }
        }));
    }

    public static void setupIntegerTextField(TextField textField) {
        setupTextField(textField, Integer::valueOf);
    }

    public static void setupURITextField(TextField textField) {
        stringConsumer = s -> {
            try {
                new URI(s);
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException(e);
            }
        };
        setupTextField(textField, stringConsumer);
    }

    public static void setupLongTextField(TextField textField) {
        setupTextField(textField, Integer::valueOf);
    }

    public static void setupBigDecimalLongTextField(TextField textField) {
        setupTextField(textField, BigDecimal::new);<commit_msg>allow broken URIs<commit_after>package de.factoryfx.javafx.util;

import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.function.Consumer;

import com.google.common.base.Strings;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;

public class TypedTextFieldHelper {

    private static Consumer<String> stringConsumer;

    private static void setupTextField(TextField textField, Consumer<String> converter) {
        textField.setTextFormatter(new TextFormatter<>(change -> {
            try {
                if (!Strings.isNullOrEmpty(change.getControlNewText())) {
                    converter.accept(change.getControlNewText());
                }
                return change;
            } catch (IllegalArgumentException e) { //javafxbug https://bugs.openjdk.java.net/browse/JDK-8081700
                return null;
            }
        }));
    }

    public static void setupIntegerTextField(TextField textField) {
        setupTextField(textField, Integer::valueOf);
    }

    public static void setupURITextField(TextField textField) {
        stringConsumer = s -> {
            try {
                new URI(s);
            } catch (URISyntaxException ignored) {
            }
        };
        setupTextField(textField, stringConsumer);
    }

    public static void setupLongTextField(TextField textField) {
        setupTextField(textField, Integer::valueOf);
    }

    public static void setupBigDecimalLongTextField(TextField textField) {
        setupTextField(textField, BigDecimal::new);
{'fraction_non_alphanumeric': 0.09057187017001546, 'fraction_numerical': 0.004327666151468315, 'mean_word_length': 2.660633484162896, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '1796869', 'n_tokens_mistral': 859, 'n_tokens_neox': 814, 'n_words': 166}