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(); }
  • 相关阅读:
    python 17 函数基础(一)
    python 17 异常
    python 16 文件操作(二)
    python 15 文件操作(一)
    python 13 字符编码
    《转》python 12 列表解析
    《转》python 11 表达式和语句
    关于int型数据的SQL模糊查询猜想
    PB学习笔记
    JSONObject.fromObject()
  • 原文地址:https://www.cnblogs.com/codingforum/p/5106720.html
Copyright © 2011-2022 走看看