ivo.ivo.vm Maven / Gradle / Ivy
package $model.getPackageName();
#foreach ( $imp in $model.getImports() )
import $imp;
#end
/**
* $model.getComment()
*
* @author $model.getAuthor()
**/
@SuppressWarnings("all")
#if ($model.isDeprecated())
@Deprecated
@ToBeRemoved(date="$model.getRemoveDate()")
#end
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = ${model.getClazzName()}.${model.getClazzName()}Builder.class)
public class $model.getClazzName() extends $model.getParentClazzName() implements $model.getInterfaceClazzName() {
private static final long serialVersionUID = ${model.getSerialVersion()}L;
/**
* Builder for the read-only ivo
*
**/
#if ($model.isDeprecated())
@Deprecated
@ToBeRemoved(date="$model.getRemoveDate()")
#end
@JsonPOJOBuilder()
public static class ${model.getClazzName()}Builder extends Abstract${model.getClazzName()}Builder<${model.getClazzName()}Builder> implements IVOBuilder {
// nothing to do here, really
}
/**
* Abstract Builder for the read-only ivo
*
* @param type of builder
**/
public abstract static class Abstract${model.getClazzName()}Builder> $model.getParentBuilder() #if ($model.isPageable())implements IPageableBuilder #end {
#foreach ( $field in $model.getAllFields() )
private $field.getTypeAsString(false) $field.getName();
#end
#if ( $model.isIdentity() && !$model.hasParentClazz() )
private String id;
/**
* the id
*
* @param pid the value to set
* @return the builder
*
**/
@SuppressWarnings("unchecked")
public E withId(String pid) {
this.id = pid;
return (E) this;
}
/**
* @return the id
**/
public String getId() {
return this.id;
}
#end
#foreach ( $field in $model.getAllFields() )
/**
#if ( $field.required )
* This field is required.
#else
* This field is optional, thus may be null.
#end
* $field.comment
*
* @param p$field.name the value to set
* @return the builder
*
**/
@Nonnull
@SuppressWarnings("unchecked")
public E with$tool.upperCaseFirst( $field.name )(#if ( $field.required )@Nonnull#else@Nullable#end $field.getTypeAsString(false) p$field.name) {
this.$field.name = p$field.name;
return (E) this;
}
/**
* @return the field value
**/
public $field.getTypeAsString(false) get$tool.upperCaseFirst( $field.name )() {
return this.$field.name;
}
#end
protected void internalFillFromIVO($model.getClazzName() ivo) {
#if ( $model.hasParentClazz() )
super.internalFillFromIVO(ivo);
#end
#foreach ( $field in $model.getAllFields() )
this.with$tool.upperCaseFirst( $field.name )(ivo.$field.name);
#end
#if ( $model.isIdentity() && !$model.hasParentClazz() )
this.withId(ivo.id);
#end
}
/**
* @return the entry
**/
#if ( $model.hasParentClazz() )
@Override
#end
@Nonnull
public $model.getClazzName() build() {
#foreach ( $field in $model.getAllFields() )
#if ( $field.required )
if (this.$field.name == null) {
throw new IllegalStateException("The attribute $field.name must not be null!");
}
#end
#end
$model.getClazzName() result = new $model.getClazzName()(this);
return result;
}
}
#foreach ( $field in $model.getAllFields() )
private final #if ( $field.javaTransientFlag )transient #end$field.getTypeAsString( false ) $field.name;
#end
#if ( $model.isIdentity() && !$model.hasParentClazz() )
private final String id;
#end
protected $model.getClazzName()(Abstract${model.getClazzName()}Builder> builder) {
#if ( $model.hasParentClazz() )
super(builder);
#end
#foreach ( $field in $model.getAllFields() )
this.$field.name = builder.$field.name;
#end
#if ( $model.isIdentity() && !$model.hasParentClazz() )
this.id = builder.id;
#end
}
#if ( $model.isIdentity() && !$model.hasParentClazz() )
@Override
public String getId() {
return this.id;
}
@Override
public long getIdAsLong() {
try {
return Long.parseLong(this.id);
} catch (NumberFormatException e) {
// string not parsable
return -1;
}
}
#end
#foreach ( $field in $model.getNoCollectionFields() )
#if ( $field.jsonTransientFlag )
@JsonIgnore
#end
#if ( $field.required )
@Nonnull
#else
@Nullable
#end
@Override
public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() {
return this.$field.name;
}
#end
#foreach ( $field in $model.getCollectionFields() )
#if ( $field.jsonTransientFlag )
@JsonIgnore
#end
#if ( $field.required )
@Nonnull
#else
@Nullable
#end
@Override
public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() {
#if( $field.collectionType == "List" )
return this.$field.name == null ? #if ( $field.required )Collections.emptyList() #else null #end: Collections.unmodifiableList(this.$field.name);
#else
return this.$field.name == null ? #if ( $field.required )Collections.emptySet() #else null #end: Collections.unmodifiableSet(this.$field.name);
#end
}
#end
#foreach ( $field in $model.getMapFields() )
#if ( $field.jsonTransientFlag )
@JsonIgnore
#end
#if ( $field.required )
@Nonnull
#else
@Nullable
#end
@Override
public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() {
#if( $field.mapType == "Map" )
return this.$field.name == null ? #if ( $field.required ) Collections.emptyMap() #else null #end: Collections.unmodifiableMap(this.$field.name);
#else
return this.$field.name == null ? null : Multimaps.unmodifiableMultimap(this.$field.name);
#end
}
#end
#if ($model.isPageable())
@SuppressWarnings("unchecked")
@Override
public IPageableBuilder createPageableBuilder() {
return (IPageableBuilder) createBuilder();
}
#end
@SuppressWarnings("unchecked")
@Override
public T createBuilder() {
${model.getClazzName()}Builder builder = new ${model.getClazzName()}Builder();
builder.internalFillFromIVO(this);
return (T) builder;
}
#if ( $model.isIdentity() && !$model.hasParentClazz() )
@Override
public String toString() {
return this.getClass().getName() + " " + this.id;
}
#end
@Override
public $model.getClazzName() clone() {
return ($model.getClazzName()) super.clone();
}
#if ( $model.isIdentity() && !$model.hasParentClazz() )
@Override
public boolean equals(Object obj) {
if(obj instanceof $model.getClazzName()) {
return Objects.equals(this.id, (($model.getClazzName())obj).id);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.id);
}
#end
#foreach ( $addition in $model.getIVOEndAddition() )
#parse($addition)
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy