zoukankan      html  css  js  c++  java
  • Enum in Java

    1. Enum Class

    public enum ContainerPropertyConstants {
        RETAILER("retailer"),
        LINED("isLined"),
        BAGGING("bagging"),
        MISSING("missing"),
        MOVABLE("movable"),
        RESERVABLE("reservable"),
        CONTAINED_DELIVERY_TOTE("hasContainerDeliveryTote"),
        DAMAGED("isDamaged"),
        DIRTY("isDirty"),
        TAINTED("isTainted"),
        CONTAINED_STOCK("hasContainedStock"),
        UNKNOWN("unknown");
        
        private String value;
        private ContainerPropertyConstants(String value) {
            this.value = value;
        }
        
        public String getValue() {
            return value;
        }
    
        @Override
        public String toString() {
            return this.getValue();
        }
    
        public static ContainerPropertyConstants getEnum(String propertyKey) {
            for(ContainerPropertyConstants v : values()) {
                if(v.getValue().equals(propertyKey.trim())) { 
                    return v;
                }
            }
            return UNKNOWN;
        }
    }

    2. Use Enum Class

        private BinAttributes getBinAttributes(Map<PropertyKey, PropertyValue> properties, BinAttributes.Builder builder) {
            properties.forEach((k, v) -> {
                switch (ContainerPropertyConstants.getEnum(k.toString())) {
                    case LINED:
                        break;
                    case MOVABLE:
                        builder.setAccessibleToPhoenix(Boolean.valueOf(v.getPropertyValue()));
                        break;
                    case RESERVABLE:
                        break;
                    case CONTAINED_DELIVERY_TOTE:
                        break;
                    case DAMAGED:
                        builder.setDamaged(Boolean.valueOf(v.getPropertyValue()));
                        break;
                    case DIRTY:
                        builder.setContaminated( Boolean.valueOf(v.getPropertyValue()));
                        break;
                    case TAINTED:
                        builder.setTainted(Boolean.valueOf(v.getPropertyValue()));
                        break;
                    case CONTAINED_STOCK:
                        break;
                    case UNKNOWN:
                        throw new IllegalArgumentException("Phoenix container property [" + k + "] not recognised.");
                    default:
                        logger.info("Currently cannot handle container property [{}]", k);
               break; } }); return builder.build(); }
  • 相关阅读:
    【笔记】隐式寻址方式(pending...)
    【笔记】有结构文件(pending...)
    【笔记】目录项(pending...)
    【笔记】主存储器
    Ubuntu 16.04 升级OpenSSH至7.7p1
    awk用法笔记
    find命令笔记
    VIM的使用
    Shell
    Linux文本处理三剑客
  • 原文地址:https://www.cnblogs.com/codingforum/p/5106720.html
Copyright © 2011-2022 走看看