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

templates.FlyWeightFactory.vm Maven / Gradle / Ivy

There is a newer version: 3.5.12
Show newest version
#* @vtlvariable name="packageName" type="java.lang.String" *#
#* @vtlvariable name="formatedFactoryName" type="java.lang.String" *#
#* @vtlvariable name="modelVersion" type="java.lang.String" *#
#* @vtlvariable name="classes" type="java.util.List" *#

package ${packageName}.impl;

import ${packageName}.${formatedFactoryName};
#foreach( $class in $classes )
import ${packageName}.${class.getName()};
#end

class Flyweight${formatedFactoryName} : ${formatedFactoryName} {

private var maxStack : Int = 1000

fun setMaxStackSize(s : Int){
maxStack = s
#foreach( $class in $classes )
stack${class.getName()}.ensureCapacity(s)
#end
}

override fun getVersion() : String { return "${modelVersion}" }

#foreach( $class in $classes )
val stack${class.getName()} = java.util.ArrayList<${class.getName()}>()
override fun create${class.getName()}() : ${class.getName()} {
if(!stack${class.getName()}.isEmpty()){
    return stack${class.getName()}.remove(0)!!
}
return ${class.getName()}Impl()
}
#end

fun restack(obj : Any){
when(obj){
#foreach( $class in $classes )
is ${class.getName()} -> {
if(maxStack < stack${class.getName()}.size()){
stack${class.getName()}.add(obj as ${class.getName()})
}
val ${class.getName()}_subs = (obj as ${class.getName()}).selectByQuery("contained[*]")
for(subClass in ${class.getName()}_subs){
restack(subClass)
}
}
#end
else -> {}
}
}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy