Java tutorial
/* * Copyright 2005-2013 iterzp.com. All rights reserved. * Support: http://www.iterzp.com * License: http://www.iterzp.com/license */ package com.iterzp.momo.utils; import org.apache.commons.beanutils.converters.AbstractConverter; /** * ? * @author canfly * @version 1.0 */ public class EnumConverterUtils extends AbstractConverter { /** */ private final Class<?> enumClass; /** * @param enumClass * */ public EnumConverterUtils(Class<?> enumClass) { this(enumClass, null); } /** * @param enumClass * * @param defaultValue * */ public EnumConverterUtils(Class<?> enumClass, Object defaultValue) { super(defaultValue); this.enumClass = enumClass; } /** * ? * * @return */ @Override protected Class<?> getDefaultType() { return this.enumClass; } /** * ? * * @param type * * @param value * * @return */ @Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected Object convertToType(Class type, Object value) { String stringValue = value.toString().trim(); return Enum.valueOf(type, stringValue); } /** * ? * * @param value * * @return */ @Override protected String convertToString(Object value) { return value.toString(); } }