程序笔记   发布时间:2022-07-21  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了枚举Switch大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

枚举Switch

  1. 枚举类
package Test;

/**
 * @program saas-rd-data-proxy
 * @author: LouisVan
 * @create: 2021/04/20 14:51
 * @date 2021-04-20 14:57
 * @author LouisVan
 */
public enum InfoNotiCEType {

    ITEM_BASE("itemBase", "商品主档"),
    STOCK("stock", "库存"),
    ITEM("item", "门店商品"),
    PRICE("price", "价格"),
    CATEGORY("category", "分类"),
    STORE_CATEGORY("store_category", "门店个性分类"),
    SHOP("shop", "店铺"),
    ;

    public String getType() {
        return type;
    }

    public void setType(String typE) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * type 类型
     */
    private String type;
    /**
     * desc 描述
     */
    private String desc;

    InfoNotiCEType(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static InfoNotiCEType geTinfoNotiCEType(String typE){
        for(InfoNotiCEType infoNotiCEType: InfoNotiCEType.values()){
            if(infoNotiCEType.getType().equals(typE)){
                return infoNotiCEType;
            }
        }
        return null;
    }
}

  1. 测试类
@Test
public void option() {

	String shopInfoNoticeReq = "{n" +
			"    "v": "v3",n" +
			"    "format": "json",n" +
			"    "sign": "e70a8e2a359544afa942e6918b6bdle6",n" +
			"    "idList": [n" +
			"        {n" +
			"            "ids": "6914973606753|1108375"n" +
			"        }n" +
			"    ],n" +
			"    "type": "price",n" +
			"    "timestamp": 1616574994683n" +
			"}";

	ShopInfoNoticeReq shopInfoNotice = JSON.parseObject(shopInfoNoticeReq, new TypeReference<ShopInfoNoticeReq>() {
	});

	switch (InfoNotiCEType.geTinfoNotiCEType(shopInfoNotice.getType())) {
		case STOCK:

			break;
		case ITEM_BASE:

			break;
		case ITEM:

			break;
		case PRICE:
			System.out.println("PRICE:" + InfoNotiCEType.PRICE + "PRICE.getType():" +
					InfoNotiCEType.PRICE.getType() + "PRICE.getDesc()" + InfoNotiCEType.PRICE.getDesc());
			break;
		case CATEGORY:

			break;
		case STORE_CATEGORY:
			break;
		case SHOP:

			break;
		default:
			break;
	}
}
// 输出: PRICE:PRICE PRICE.getType():price PRICE.getDesc():价格

大佬总结

以上是大佬教程为你收集整理的枚举Switch全部内容,希望文章能够帮你解决枚举Switch所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。