码迷,mamicode.com
首页 > 编程语言 > 详细

Enum in Java

时间:2016-01-06 21:38:33      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }

Enum in Java

标签:

原文地址:http://www.cnblogs.com/codingforum/p/5106720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!