All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mindee.product.nutritionfactslabel.NutritionFactsLabelV1AddedSugar Maven / Gradle / Ivy

The newest version!
package com.mindee.product.nutritionfactslabel;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mindee.parsing.SummaryHelper;
import com.mindee.parsing.standard.BaseField;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;

/**
 * The amount of added sugars in the product.
 */
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public class NutritionFactsLabelV1AddedSugar extends BaseField {

  /**
   * DVs are the recommended amounts of added sugars to consume or not to exceed each day.
   */
  @JsonProperty("daily_value")
  Double dailyValue;
  /**
   * The amount of added sugars per 100g of the product.
   */
  @JsonProperty("per_100g")
  Double per100G;
  /**
   * The amount of added sugars per serving of the product.
   */
  @JsonProperty("per_serving")
  Double perServing;

  public boolean isEmpty() {
    return (
        dailyValue == null
        && per100G == null
        && perServing == null
      );
  }

  /**
   * Output the object in a format suitable for inclusion in an rST field list.
   */
  public String toFieldList() {
    Map printable = this.printableValues();
    return String.format("  :Daily Value: %s%n", printable.get("dailyValue"))
        + String.format("  :Per 100g: %s%n", printable.get("per100G"))
        + String.format("  :Per Serving: %s%n", printable.get("perServing"));
  }

  @Override
  public String toString() {
    Map printable = this.printableValues();
    return String.format("Daily Value: %s", printable.get("dailyValue"))
      + String.format(", Per 100g: %s", printable.get("per100G"))
      + String.format(", Per Serving: %s", printable.get("perServing"));
  }

  private Map printableValues() {
    Map printable = new HashMap<>();

    printable.put(
        "dailyValue",
        SummaryHelper.formatAmount(this.dailyValue)
    );
    printable.put(
        "per100G",
        SummaryHelper.formatAmount(this.per100G)
    );
    printable.put(
        "perServing",
        SummaryHelper.formatAmount(this.perServing)
    );
    return printable;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy