enum枚举使用

来源:互联网 发布:ios 免费 日程软件 编辑:程序博客网 时间:2024/04/29 12:49
enum 枚举的使用package com.lwl.api.service.standard.enums;import com.google.gson.annotations.SerializedName;import java.io.Serializable;import java.util.HashMap;import java.util.Map;/** * Created by tkzc on 2016/12/14. */public enum QuoteType implements Serializable {    @SerializedName("0")    All("默认",0),    @SerializedName("1")    TL("整车",1),    @SerializedName("2")    LTL("零担",2);    private String name;    private int index;    private QuoteType(String name, int index) {        this.name = name;        this.index = index;    }    public  String getDesc(){        return  this.name.toString();    }    public  Short value (){        return    Short.valueOf(String.valueOf(this.index));    }    private static final Map<String, QuoteType> stringToEnum = new HashMap<String,QuoteType>();    static {        // Initialize map from constant name to enum constant        for(QuoteType myenum : values()) {            stringToEnum.put(myenum.value().toString(), myenum);        }    }    public  static QuoteType valueOf(Short s){        return  stringToEnum.get(s.toString());    }}
0 0
原创粉丝点击