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

templates.EqualsMethod.vm Maven / Gradle / Ivy

There is a newer version: 3.5.12
Show newest version
#* @vtlvariable name="currentClass" type="org.eclipse.emf.ecore.EClass" *#
#* @vtlvariable name="FQNHelper" type="org.kevoree.modeling.kotlin.generator.ProcessorHelper" *#
#* @vtlvariable name="ctx" type="org.kevoree.modeling.kotlin.generator.GenerationContext" *#


override fun deepModelEquals(similarObj : Any?) : Boolean {
    if(!modelEquals(similarObj)){
        return false
    }
    val similarObjCasted = similarObj as ${FQNHelper.fqn($ctx, $currentClass)}
    #foreach( $sub in $currentClass.getEAllContainments())
        #if($sub.isMany())
        for(subElement in get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}()){
        #if($sub.getEReferenceType().getEIDAttribute())
            val foundedElement = similarObjCasted.find${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}ByID(subElement.get${sub.getEReferenceType().getEIDAttribute().getName().substring(0, 1).toUpperCase()}${sub.getEReferenceType().getEIDAttribute().getName().substring(1)}())
            if(foundedElement == null || foundedElement != subElement){ return false }
        #else
            //todo optimize with pre sort on collection
            var lookEqualsSub = false
            for(subElement2 in similarObjCasted.get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}()){
                if(subElement.deepModelEquals(subElement2)){
                    lookEqualsSub = true
                }
            }
            if(!lookEqualsSub){return false }
        #end
        }
        #end
    #end
    return true
}

override fun modelEquals(similarObj : Any?) : Boolean {

#if($ctx.getJS())
if(similarObj == null || !(similarObj is ${FQNHelper.fqn($ctx, $currentClass)}) || !(similarObj is ${FQNHelper.fqn($ctx, $currentClass.getEPackage())}.impl.${currentClass.getName()}Impl) ){
#else
if(similarObj == null || !(similarObj is ${FQNHelper.fqn($ctx, $currentClass)})){
#end

        return false
    }
    val similarObjCasted = similarObj as ${FQNHelper.fqn($ctx, $currentClass)}
    #foreach( $att in $currentClass.eAllAttributes )
       if(get${att.getName().substring(0, 1).toUpperCase()}${att.getName().substring(1)}() != similarObjCasted.get${att.getName().substring(0, 1).toUpperCase()}${att.getName().substring(1)}()){
            return false
       }
    #end
    #foreach( $sub in $currentClass.getEAllContainments())
        #if($sub.isMany())
            if(get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}().size() != similarObjCasted.get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}().size()){
                return false
            }
        #else
            if(get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}() != similarObjCasted.get${sub.getName().substring(0, 1).toUpperCase()}${sub.getName().substring(1)}()){
                return false
            }
        #end
    #end
    return true
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy