com.junly.common.enums.UserTypeEnums.java Source code

Java tutorial

Introduction

Here is the source code for com.junly.common.enums.UserTypeEnums.java

Source

/*
 * ?(C) lijun2016-2020
 * Copyright 2016-2020 Zhejiang lijun Technology Co., Ltd.
 *  
 * This software is the confidential and proprietary information of
 * Zhejiang lijun Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Zhejiang lijun
 */
package com.junly.common.enums;

import org.apache.commons.lang.StringUtils;

/** <p class="detail">
 * 
 * </p>
 * @ClassName: UserTypeEnums 
 * @version V1.0  
 * @date 2017322 
 * @author junly
 * Copyright2016lijun.com,Inc.Allrightsreserved
 */
public enum UserTypeEnums {

    SYSTEM_MANAGER(0, "??"), DEALER(1, ""), MEMBER(2, ""),;

    private int code;

    private String detail;

    /** <p class="detail">
    * ?web
    * </p>
    * @author panwuhai
    * @date 2016518 
    * @return    
    */
    public boolean isWebMember() {
        switch (this) {
        case SYSTEM_MANAGER:
        case DEALER:
            return true;
        default:
            return false;
        }
    }

    /** <p class="detail">
    * app
    * </p>
    * @author panwuhai
    * @date 2016518 
    * @return    
    */
    public boolean isAppMember() {
        switch (this) {
        case MEMBER:
            return true;
        default:
            return false;
        }
    }

    UserTypeEnums(int code, String detail) {
        this.code = code;
        this.detail = detail;
    }

    /**
     * 
     * 
     * @param code
     * @return
     */
    public static UserTypeEnums getEnumByCode(Integer code) {

        if (null != code) {
            for (UserTypeEnums activitie : UserTypeEnums.values()) {
                if (code == activitie.getCode()) {
                    return activitie;
                }
            }
        }
        return null;
    }

    public static String getDetailByCode(Integer code) {

        if (null != code) {
            for (UserTypeEnums activitie : UserTypeEnums.values()) {
                if (code == activitie.getCode()) {
                    return activitie.getDetail();
                }
            }
        }
        return null;
    }

    /**
     * @return code
     */

    public int getCode() {
        return code;
    }

    /**
     * @param code
     */
    public void setCode(int code) {
        this.code = code;
    }

    /**
     * @return the detail
     */
    public String getDetail() {
        return detail;
    }

    /**
     * @param detail
     *            the detail to set
     */
    public void setDetail(String detail) {
        this.detail = detail;
    }

    /** <p class="detail">
    * ???,
    * </p>
    * @author panwuhai
    * @date 201667 
    * @return 
    */
    public static String toSelectJsonShow() {
        StringBuilder builder = new StringBuilder("[");
        for (UserTypeEnums activitie : UserTypeEnums.values()) {
            builder.append("{");
            builder.append("\"name\"").append(":\"").append(activitie.name()).append("\",");
            builder.append("\"code\"").append(":\"").append(activitie.getCode()).append("\",");
            builder.append("\"detail\"").append(":\"").append(activitie.getDetail()).append("\"},");
        }
        String result = StringUtils.substring(builder.toString(), 0, builder.length() - 1);
        return result + "]";
    }

}