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

webpiecesxxxxxpackage.db.EducationEnum Maven / Gradle / Ivy

Go to download

Someone forgot to fill this in. See http://stackoverflow.com/questions/38272550/how-to-fail-the-gradle-build-if-subproject-is-missing-a-property

There is a newer version: 2.1.28
Show newest version
package webpiecesxxxxxpackage.db;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import org.webpieces.router.api.extensions.ObjectStringConverter;

public enum EducationEnum {

	KINDERGARTEN('k', "Kindergarten"), 
	ELEMENTARY('e', "Elementary School"), 
	MIDDLE_SCHOOL('m', "Middle School"), 
	HIGH_SCHOOL('h', "High School"), 
	COLLEGE('c', "College");

	private final static Map enums = new HashMap<>();
	
	static {
		for(EducationEnum level : EducationEnum.values()) {
			enums.put(level.getDbCode(), level);
		}
	}
	
	//could use an int....
	private Character dbCode;
	private String guiLabel;
	
	private EducationEnum(Character dbCode, String guiLabel) {
		this.dbCode = dbCode;
		this.guiLabel = guiLabel;
	}

	public Character getDbCode() {
		return dbCode;
	}

	public void setDbCode(Character dbCode) {
		this.dbCode = dbCode;
	}
	
	public static EducationEnum lookup(Character code) {
		return enums.get(code);
	}
	
	public String getGuiLabel() {
		return guiLabel;
	}

	@Converter(autoApply = true)
	public static class EducationConverter implements AttributeConverter  {

	    public Character convertToDatabaseColumn( EducationEnum value ) {
	        if ( value == null ) {
	            return null;
	        }

	        return value.getDbCode();
	    }

	    public EducationEnum convertToEntityAttribute( Character value ) {
	        if ( value == null ) {
	            return null;
	        }

	        return EducationEnum.lookup( value );
	    }
	}
	
	public static class WebConverter implements ObjectStringConverter {

	    public String objectToString( EducationEnum value ) {
	        if ( value == null ) {
	            return null;
	        }

	        return value.getDbCode()+"";
	    }

	    public EducationEnum stringToObject( String value ) {
	        if ( value == null ) {
	            return null;
	        }

	        if(value.length() != 1)
	        	throw new IllegalArgumentException("cannot convert="+value);
	        Character c = value.charAt(0);
	        return EducationEnum.lookup( c );
	    }

		@Override
		public Class getConverterType() {
			return EducationEnum.class;
		}

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy