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

org.unix4j.convert.EnumConverters Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.convert;

public class EnumConverters {
	public static class StringToEnumConverter> implements ValueConverter {
		private final Class enumClass;
		public StringToEnumConverter(Class enumClass) {
			this.enumClass = enumClass;
		}
		@Override
		public E convert(Object value) throws IllegalArgumentException {
			if (value != null) {
				final String name = value.toString();
				try {
					return Enum.valueOf(enumClass, name);
				} catch (IllegalArgumentException e) {
					return null;
				}
			}
			return null;
		}
	};
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy