PriceInfo.java 2.17 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  aQute.bnd.annotation.ProviderType
 *  org.apache.sling.api.wrappers.ValueMapDecorator
 */
package com.adobe.cq.commerce.api;

import aQute.bnd.annotation.ProviderType;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.sling.api.wrappers.ValueMapDecorator;

@ProviderType
public class PriceInfo
extends ValueMapDecorator {
    public static final String MIN_QUANTITY = "minQuantity";
    private BigDecimal amount;
    private Currency currency;
    private Locale locale;

    @Deprecated
    public PriceInfo(BigDecimal amount, Currency currency) {
        super(new HashMap());
        this.amount = amount;
        this.currency = currency;
        this.locale = null;
    }

    public PriceInfo(BigDecimal amount, Locale locale) {
        super(new HashMap());
        this.amount = amount;
        this.currency = Currency.getInstance(locale);
        this.locale = locale;
    }

    public PriceInfo(BigDecimal amount, Locale locale, Currency currency) {
        super(new HashMap());
        this.amount = amount;
        this.locale = locale;
        this.currency = currency;
    }

    public BigDecimal getAmount() {
        return this.amount;
    }

    public long getQuantity() {
        return (Long)this.get("minQuantity", (Object)1);
    }

    public Locale getLocale() {
        return this.locale;
    }

    public Currency getCurrency() {
        return this.currency;
    }

    public String getFormattedString() {
        NumberFormat nf;
        if (this.amount == null) {
            return "";
        }
        if (this.locale != null) {
            nf = NumberFormat.getCurrencyInstance(this.locale);
            nf.setCurrency(this.currency);
        } else {
            nf = NumberFormat.getCurrencyInstance();
            nf.setCurrency(this.currency);
            nf.setMinimumFractionDigits(2);
            nf.setMaximumFractionDigits(2);
        }
        return nf.format(this.amount);
    }

    public String toString() {
        return this.getFormattedString();
    }
}