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

cturing.sds-aspect-model-java-generator.1.0.1.source-code.java-enumeration-class-body-lib.vm Maven / Gradle / Ivy

#macro( javaEnumerationClassBody )
$importTracker.importExplicit( $Optional )
$importTracker.importExplicit( $Arrays )
#if( $enableJacksonAnnotations )
    $importTracker.importExplicit( $JsonValue )
    $importTracker.importExplicit( $JsonFormat )
    $importTracker.importExplicit( $JsonCreator )
#end

/**
* Generated class {@link ${enumeration.name}}.
*/
#if( $enableJacksonAnnotations )@JsonFormat(shape = JsonFormat.Shape.OBJECT) #end
public enum ${enumeration.name} {
#foreach( $value in $enumeration.values )
    $util.generateEnumKey($enumeration.dataType, $value, $importTracker)($util.generateEnumValue($enumeration.getDataType(), $value, false, $importTracker))
    #if( $foreach.hasNext), #end
#end;

private $dataType value;

$className($dataType value) {
    this.value = value;
}

#if( $enableJacksonAnnotations )@JsonCreator #end
static ${className} enumDeserializationConstructor($dataType value) {
    return fromValue(value).orElseThrow(() -> new EnumAttributeNotFoundException("Tried to parse value \"" + value + "\", but there is no enum field like that in ${className}"));
}

#if( $enableJacksonAnnotations )@JsonValue #end
public $dataType getValue() {
    return value;
}

#if( $State.isAssignableFrom( $enumeration.class ) )
public static $className getDefaultValue() {
    #set( $state = $State.cast( $enumeration ) )
    return $util.generateEnumKey( $enumeration.getDataType(), $state.getDefaultValue(), $importTracker );
}
#end

public static Optional<$className> fromValue($dataType value) {
    return Arrays.stream(${className}.values())
        .filter(enumValue -> compareEnumValues(enumValue, value))
        .findAny();
}

private static boolean compareEnumValues($className enumValue, $dataType value) {
    return $util.generateFilterCompare( $enumeration.getDataType() );
}

}
#end




© 2015 - 2024 Weber Informatics LLC | Privacy Policy