<commit_before>package com.juanpabloprado.ecommerceapi.product;

import com.juanpabloprado.ecommerceapi.integration.agenty.dto.Result;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
  @Override public Product fromIntegration(Result result) {
    try {
      Number number = NumberFormat.getCurrencyInstance(new Locale("es", "MX")).parse(result.getPrice());
      BigDecimal price = new BigDecimal(number.doubleValue());

      return new Product(result.getName(), price, null, result.getImageUrl());
    } catch (Exception ex ) {
      return new Product(result.getName(), new BigDecimal("0.00"), result.getPrice(), result.getImageUrl());
    }

  }
}<commit_msg>Parse correctly prices from amazon e.g. $400.61 - $1,418.64 to 400.61<commit_after>package com.juanpabloprado.ecommerceapi.product;

import com.juanpabloprado.ecommerceapi.integration.agenty.dto.Result;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
  @Override public Product fromIntegration(Result result) {
    try {
      String firstPrice = getFirstWord(result.getPrice());
      Number number =
          NumberFormat.getCurrencyInstance(new Locale("es", "MX")).parse(firstPrice);
      BigDecimal price = new BigDecimal(number.doubleValue()).setScale(2, BigDecimal.ROUND_HALF_EVEN);;

      return new Product(result.getName(), price, null, result.getImageUrl());
    } catch (Exception ex) {
      return new Product(result.getName(), new BigDecimal("0.00"), result.getPrice(),
          result.getImageUrl());
    }
  }

  private String getFirstWord(String text) {
    if (text.indexOf(' ') > -1) {
      return text.substring(0, text.indexOf(' '));
    } else {
      return text;
    }
  }
}
{'fraction_non_alphanumeric': 0.12297570850202429, 'fraction_numerical': 0.012651821862348178, 'mean_word_length': 4.416438356164384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4942979', 'n_tokens_mistral': 599, 'n_tokens_neox': 581, 'n_words': 124}