Пример #1
0
    @Override
    protected Map<String, Double> doInBackground(Void... params) {
      Map<String, Double> results = new HashMap<>();

      for (Map.Entry<String, Double> entry : FoodItem.getAllDensities().entrySet()) {
        String[] words = food.getName().split("\\s+");
        for (String word : words) {
          // boolean contains = entry.getKey().toLowerCase().matches(".*\\b" + word.toLowerCase() +
          // "\\b.*");
          String cleanedWord = word.replaceAll("[^\\w]", "");
          if (cleanedWord.equals("")) {
            continue;
          }
          boolean contains =
              entry.getKey().toLowerCase().matches(".*\\b" + cleanedWord.toLowerCase() + "\\b.*");
          if (contains) {
            results.put(entry.getKey(), entry.getValue());
          }
        }
      }

      return results;
    }