Package io.avaje.validation.generator
Record Class SubTypeWriter.SubTemplate
java.lang.Object
java.lang.Record
io.avaje.validation.generator.SubTypeWriter.SubTemplate
- Enclosing class:
SubTypeWriter
@JStache(template="package {{packageName}};\n\n{{#imports}}\nimport {{.}};\n{{/imports}}\n\n@Generated(\"avaje-validation-generator\")\npublic class {{shortName}}ValidationAdapter implements ValidationAdapter<{{shortType}}> {\n\n{{#subtypes}}\n private final ValidationAdapter<{{.}}> subAdapter{{@index}};\n{{/subtypes}}\n\n public {{shortName}}ValidationAdapter(ValidationContext ctx) {\n{{#subtypes}}\n this.subAdapter{{@index}} = ctx.adapter({{.}}.class);\n{{/subtypes}}\n }\n\n @Override\n public boolean validate({{shortType}} value, ValidationRequest request, String field) {\n{{#switchValid}}\n return switch(value) {\n case null -> true;\n {{#subtypes}}\n case {{.}} val -> subAdapter{{@index}}.validate(val, request, field);\n {{/subtypes}}\n {{^sealed}}\n default -> true;\n {{/sealed}}\n };\n{{/switchValid}}\n{{^switchValid}}\n{{#subtypes}}\n if (value instanceof {{.}} val) {\n return subAdapter{{@index}}.validate(val, request, field);\n }\n{{/subtypes}}\n return true;\n{{/switchValid}}\n }\n}\n")
public static record SubTypeWriter.SubTemplate(String packageName, Set<String> imports, String shortName, String shortType, List<String> subtypes, boolean switchValid, boolean sealed)
extends Record
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.imports()Returns the value of theimportsrecord component.Returns the value of thepackageNamerecord component.booleansealed()Returns the value of thesealedrecord component.Returns the value of theshortNamerecord component.Returns the value of theshortTyperecord component.subtypes()Returns the value of thesubtypesrecord component.booleanReturns the value of theswitchValidrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SubTemplate
public SubTemplate(String packageName, Set<String> imports, String shortName, String shortType, List<String> subtypes, boolean switchValid, boolean sealed) Creates an instance of aSubTemplaterecord class.- Parameters:
packageName- the value for thepackageNamerecord componentimports- the value for theimportsrecord componentshortName- the value for theshortNamerecord componentshortType- the value for theshortTyperecord componentsubtypes- the value for thesubtypesrecord componentswitchValid- the value for theswitchValidrecord componentsealed- the value for thesealedrecord component
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
packageName
Returns the value of thepackageNamerecord component.- Returns:
- the value of the
packageNamerecord component
-
imports
Returns the value of theimportsrecord component.- Returns:
- the value of the
importsrecord component
-
shortName
Returns the value of theshortNamerecord component.- Returns:
- the value of the
shortNamerecord component
-
shortType
Returns the value of theshortTyperecord component.- Returns:
- the value of the
shortTyperecord component
-
subtypes
Returns the value of thesubtypesrecord component.- Returns:
- the value of the
subtypesrecord component
-
switchValid
public boolean switchValid()Returns the value of theswitchValidrecord component.- Returns:
- the value of the
switchValidrecord component
-
sealed
public boolean sealed()Returns the value of thesealedrecord component.- Returns:
- the value of the
sealedrecord component
-