<commit_before>package name.abuchen.portfolio.ui.util;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import name.abuchen.portfolio.model.Values;
import name.abuchen.portfolio.ui.Messages;

import org.eclipse.core.databinding.conversion.IConverter;

public class StringToCurrencyConverter implements IConverter
{
    private static final Pattern PATTERN = Pattern.compile("^([\\d.]*)(,(\\d*))?$"); //$NON-NLS-1$
    private final NumberFormat full = new DecimalFormat("#,###"); //$NON-NLS-1$

    private final double factor;

    public StringToCurrencyConverter(Values<?> type)
    {
        this.factor = type.divider();
    }

    @Override
    public Object getFromType()
    {
        return String.class;
    }

    @Override
    public Object getToType()
    {
        return long.class;
    }

    @Override
    public Object convert(Object fromObject)
    {
        try
        {
            String value = (String) fromObject;

            Matcher m = PATTERN.matcher(String.valueOf(value));
            if (!m.matches())
                throw new IllegalArgumentException(String.format(Messages.CellEditor_NotANumber, value));
<commit_msg>allow entries with leading/trailing spaces in Buy/Sell Dialog number text fields<commit_after>package name.abuchen.portfolio.ui.util;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import name.abuchen.portfolio.model.Values;
import name.abuchen.portfolio.ui.Messages;

import org.eclipse.core.databinding.conversion.IConverter;

public class StringToCurrencyConverter implements IConverter
{
    private static final Pattern PATTERN = Pattern.compile("^([\\d.]*)(,(\\d*))?$"); //$NON-NLS-1$
    private final NumberFormat full = new DecimalFormat("#,###"); //$NON-NLS-1$

    private final double factor;

    public StringToCurrencyConverter(Values<?> type)
    {
        this.factor = type.divider();
    }

    @Override
    public Object getFromType()
    {
        return String.class;
    }

    @Override
    public Object getToType()
    {
        return long.class;
    }

    @Override
    public Object convert(Object fromObject)
    {
        try
        {
            String value = (String) fromObject;
            value = value.trim();
            Matcher m = PATTERN.matcher(String.valueOf(value));
            if (!m.matches())
                throw new IllegalArgumentException(String.format(Messages.CellEditor_NotANumber, value));

{'fraction_non_alphanumeric': 0.11664133738601824, 'fraction_numerical': 0.001519756838905775, 'mean_word_length': 3.025993883792049, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1895718', 'n_tokens_mistral': 772, 'n_tokens_neox': 752, 'n_words': 166}