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

com.spring.boxes.dollar.support.locale.Currency Maven / Gradle / Ivy

package com.spring.boxes.dollar.support.locale;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.EnumSet;
import java.util.Map;
import java.util.Set;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum Currency {

    /**
     * 人民币币种
     */
    CNY("CNY", "¥", "人民币"),

    /**
     * 美元币种
     */
    USD("USD", "$", "美元"),

    /**
     * 港币币种
     */
    HKD("HKD", "HK$", "港币"),

    /**
     * 日元币种
     */
    JPY("JPY", "¥", "日币"),

    /**
     * 新币币种
     */
    SGD("SGD", "$", "新币"),

    /**
     * 欧元
     */
    EUR("EUR", "€", "欧元"),

    /**
     * 韩币
     */
    KRW("KRW", "KRW", "韩币");


    /**
     * 币种
     */
    private final String currency;

    /**
     * 币种符号
     */
    private final String symbol;

    /**
     * 简述
     */
    private final String brief;

    /**
     * 最小单位为元的币种
     */
    private static final Set MIN_UNIT_YUAN;
    private static final Map CURRENCY_ENUM_MAP;


    static {
        CURRENCY_ENUM_MAP = Maps.newHashMapWithExpectedSize(128);
        for (Currency currencyEnum : EnumSet.allOf(Currency.class)) {
            CURRENCY_ENUM_MAP.put(currencyEnum.currency, currencyEnum);
        }
        MIN_UNIT_YUAN = ImmutableSet.of(KRW, JPY);
    }

    /**
     * 根据currency 获取  GlobalCurrencyEnum枚举值
     *
     * @param currency 币种参数
     * @return GlobalCurrencyEnum by currency mapping
     */
    public static Currency getCurrencyEnumBy(String currency) {
        return CURRENCY_ENUM_MAP.get(currency);
    }

    /**
     * 获取所有已存在的币种枚举
     *
     * @return key:币种 value:币种对应的枚举
     */
    public static Map getCurrencyEnumMap() {
        return CURRENCY_ENUM_MAP;
    }

    /**
     * 获取最小结算币种是元的地区
     */
    public static Set getMinUnitYuanCurrency() {
        return MIN_UNIT_YUAN;
    }

    /**
     * 判断是否是最小币种元
     *
     * @param currency 目前韩币和日币最小单位元,返回ture。null和其他返回false
     */
    public static boolean isMinUnitYuanCurrency(String currency) {
        if (currency == null) {
            return false;
        }
        return MIN_UNIT_YUAN.stream().anyMatch(p -> p.getCurrency().equals(currency.toUpperCase()));
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy