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

com.cn.lp.common.context.ItemCodes Maven / Gradle / Ivy

The newest version!
package com.cn.lp.common.context;

import com.cn.lp.common.utils.StringAide;

import java.util.HashMap;
import java.util.Map;

/**
 * itemID 集合接口
 *
 * @author qirong
 * @date 2018/11/16
 */
public class ItemCodes {

    private static final Map codeMap = new HashMap<>();

    /**
     * 根据ID找ItemCode
     *
     * @param id
     * @return
     */
    public static ItemCode of(int id) {
        return codeMap.get(id);
    }

    /**
     * 注册ID, 并识别ID是否重复
     *
     * @param code
     */
    static void registerCode(ItemCode code) {
        ItemCode old = codeMap.put(code.getID(), code);
        if (old != null) {
            IllegalArgumentException e = new IllegalArgumentException(StringAide.format("{}.{} 与 {}.{} id 都为 {}",
                code.getClass(), code, old.getClass(), old, old.getID()
            ));
            e.printStackTrace();
            throw e;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy