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

Micronaut.modelEnum.mustache Maven / Gradle / Ivy

The newest version!
{{#serdeable}}@io.micronaut.serde.annotation.Serdeable
{{/serdeable}}
public enum {{#nameInPascalCase}}{{{nameInPascalCase}}}{{/nameInPascalCase}}{{^nameInPascalCase}}{{{classname}}}{{/nameInPascalCase}} {

{{#allowableValues}}{{#enumVars}}	{{{name}}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
{{#allowableValues}}{{#enumVars}}
	public static final {{dataType}} {{{name}}}_VALUE = {{{value}}};{{/enumVars}}{{/allowableValues}}

	private final {{dataType}} value;

	private {{#nameInPascalCase}}{{{nameInPascalCase}}}{{/nameInPascalCase}}{{^nameInPascalCase}}{{{classname}}}{{/nameInPascalCase}}({{dataType}} value) {
		this.value = value;
	}

	@com.fasterxml.jackson.annotation.JsonCreator
	public static {{#nameInPascalCase}}{{{nameInPascalCase}}}{{/nameInPascalCase}}{{^nameInPascalCase}}{{{classname}}}{{/nameInPascalCase}} toEnum({{dataType}} value) {
		return toOptional(value).orElseThrow(() -> new IllegalArgumentException("Unknown value '" + value + "'."));
	}

	public static java.util.Optional<{{#nameInPascalCase}}{{{nameInPascalCase}}}{{/nameInPascalCase}}{{^nameInCamelCase}}{{{classname}}}{{/nameInCamelCase}}> toOptional({{dataType}} value) {
		return java.util.Arrays
				.stream(values())
				.filter(e -> e.value.equals(value))
				.findAny();
	}

	@com.fasterxml.jackson.annotation.JsonValue
	public {{dataType}} getValue() {
		return value;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy