All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.cast.castor.EnumCastor Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.cast.castor;

import panda.cast.CastContext;

@SuppressWarnings("rawtypes")
public class EnumCastor extends AnySingleCastor {
	public EnumCastor(Class toType) {
		super(toType);
	}

	@Override
	@SuppressWarnings("unchecked")
	protected Enum castValue(Object value, CastContext context) {
		if (value instanceof CharSequence) {
			try {
				return Enum.valueOf((Class)getToType(), value.toString());
			}
			catch (IllegalArgumentException e) {
				return castError(value, context, e);
			}
		}
		return castError(value, context);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy