User: vancek
Date: 06/04/23 19:28:00
Added: andromda-ejb3/src/main/resources/templates/ejb3
GlobalMacros.vm
Log:
initial revision - macros used in value objects - from spring cartridge
Revision Changes Path
1.1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/GlobalMacros.vm
Index: GlobalMacros.vm
===================================================================
##
## This macro will render the equals() method
## If an entity is rendered, the attributeSet consists of the identifiers,
## if an value type is renderer, the attributeSet consists of all attributes
##
#macro (renderEqualsMethod $class $className $attributeSet)
public boolean equals(Object object)
{
#if ($attributeSet.empty)
return super.equals(object);
#else
if (this == object)
{
return true;
}
if (!(object instanceof $className))
{
return false;
}
final $className that = ($className)object;
#foreach ($attribute in $attributeSet)
#set ($idType = $attribute.type)
#if ($idType.primitive)
if (this.$attribute.name != that.${attribute.getterName}())
{
return false;
}
#elseif ($idType.arrayType)
if (!java.util.Arrays.equals(this.$attribute.name, that.${attribute.getterName}()))
{
return false;
}
#else
if (this.$attribute.name == null || that.${attribute.getterName}() == null || !this.${attribute.name}.equals(that.${attribute.getterName}()))
{
return false;
}
#end
#end
return true;
#end
}
#end
##
## This macro will render the hashCode() method
## If an entity is rendered, the attributeSet consists of the identifiers,
## if an value type is renderer, the attributeSet consists of all attributes
##
#macro (renderHashCodeMethod $class $attributeSet)
public int hashCode()
{
#if ($attributeSet.empty)
return super.hashCode();
#else
#if ($class.generalization)
int hashCode = super.hashCode();
#else
int hashCode = 0;
#end
#foreach ($attribute in $attributeSet)
#set ($attrType = $attribute.type)
#if ($attribute.getterSetterTypeName == "boolean")
hashCode = 29 * hashCode + (${attribute.name} ? 1 : 0);
#elseif ($attrType.arrayType)
// arrays are not part of the hashCode calculation
#elseif ($attrType.primitive)
hashCode = 29 * hashCode + (int)${attribute.name};
#else
hashCode = 29 * hashCode + (${attribute.name} == null ? 0 : ${attribute.name}.hashCode());
#end## if
#end## foreach
return hashCode;
#end## $attributeSet.empty
}
#end
|