コード例 #1
0
  @Override
  public boolean conformes(Product data) {
    String[] argParts = this.argument.split(" ");
    String mathSymbol = argParts[0];

    // in g or ml
    double polylAmount = -1.0;

    for (EnergyNutrientsVitamins nutrient :
        data.getIngredientsAndAllergens().getEnergyNutrientsVitamins()) {
      if ((nutrient.getNutritionalValueReference() == 100.0)
          && ((((nutrient.getNutritionalValueReferenceUnit() == ServingSizeUnitOfMeasureCode.GR)
              || (nutrient.getNutritionalValueReferenceUnit()
                  == ServingSizeUnitOfMeasureCode.ML))))) {

        for (NutritionalContentItem content : nutrient.getNutrients()) {
          if (content.getNutritionalContent() == NutritionalContentCode.POLYL) {
            polylAmount = content.getNutritionalContentQuantityContained();
            if (content.getNutritionalContentQuantityContain() == ServingSizeUnitOfMeasureCode.EMPTY
                || content.getNutritionalContentQuantityContain() == PTN) {
              return false;
            } else {
              break;
            }
          }
        }
        break;
      }
    }

    if (polylAmount < 0) {
      // something went wrong, or there are simply no POLYL contained
      return false;
    }

    double amount = -1.0;
    if (argParts[1].contains("%")) {
      amount = Double.parseDouble(argParts[1].replace("%", ""));
      // here we get the percentage of polyl in the product
      // EDIT: if we use the polyl per 100 gr, then we don't need this
      // polylAmount = (polylAmount / convertNetWeight(data)) * 100;
    } else {
      amount = Double.parseDouble(argParts[1].replace("g", ""));
    }

    if (mathSymbol.equals("<")) {
      return polylAmount < amount;
    } else if (mathSymbol.equals("=")) {
      return polylAmount == amount;
    } else if (mathSymbol.equals(">")) {
      return polylAmount > amount;
    } else {
      Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)
          .log(Level.WARNING, "Allowed operators: < OR > OR =. Chosen operator: {0}", mathSymbol);
      return false;
    }
  }
コード例 #2
0
  /**
   * To gramm or ml.
   *
   * @param data
   * @return
   */
  private double convertNetWeight(Product data) {
    double netWeight = -1.0;

    List<NetWeightEntity> netWeights = data.getStorageAndUsage().getNetWeight();
    if (!netWeights.isEmpty() && (netWeights.get(0).getNetWeightUnit() != null)) {
      NetWeightEntity e = netWeights.get(0);
      netWeight = e.getNetWeightValue();
      switch (e.getNetWeightUnit()) {
        case KG:
          // to get to g
          netWeight *= 1000;
          break;
        case LT:
          // to get to ml
          netWeight *= 1000;
          break;
        default:
          break;
      }
    }
    return netWeight;
  }