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

com.github.stefanbirkner.editors.mapper.EnumMapper Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.github.stefanbirkner.editors.mapper;

import static java.lang.Enum.valueOf;

/**
 * An {@code EnumMapper} maps between enums to text and vice versa by using their names.
 * 
 * @author Stefan Birkner 
 * 
 * @param 
 *            the supported type.
 * @since 2.0.0
 */
public class EnumMapper> implements Mapper {
	private final Class type;

	public EnumMapper(Class type) {
		this.type = type;
	}
	
	public E getValueForText(String text) {
		return (text == null) ? null : valueOf(type, text);
	}

	public String getTextForValue(E value) {
		return (value == null) ? null : value.name();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy