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

templates.dmn2java.tree.decisionTableRuleOutput.ftl Maven / Gradle / Ivy

There is a newer version: 8.7.3
Show newest version
<#if javaPackageName?has_content>
package ${javaPackageName};


import java.util.*;

@javax.annotation.Generated(value = {"decisionTableRuleOutput.ftl", "${modelRepository.name(drgElement)}"})
public class ${javaClassName} extends ${transformer.abstractRuleOutputClassName()} {
    <#if modelRepository.isDecisionTableExpression(drgElement)>
    <@addPrivateFields drgElement />
    

    public ${javaClassName}(boolean matched) {
        super(matched);
    }

    <#if modelRepository.isDecisionTableExpression(drgElement)>
    <@addAccessors drgElement />

    <@addEqualsAndHashCode drgElement />

    <@addToString drgElement />
    <@addSortMethod drgElement />
    
}
<#macro addPrivateFields drgElement>
    <#assign expression = modelRepository.expression(drgElement)>
    <#list expression.output as output>
    private ${transformer.outputClauseClassName(drgElement, output)} ${transformer.outputClauseVariableName(drgElement, output)};
    <#if modelRepository.isOutputOrderHit(expression.hitPolicy)>
    private Integer ${transformer.outputClausePriorityVariableName(drgElement, output)};
    
    


<#macro addAccessors drgElement>
    <#assign expression = modelRepository.expression(drgElement)>
    <#list expression.output as output>
    public ${transformer.outputClauseClassName(drgElement, output)} ${transformer.getter(drgElement, output)} {
        return this.${transformer.outputClauseVariableName(drgElement, output)};
    }
    public void ${transformer.setter(drgElement, output)}(${transformer.outputClauseClassName(drgElement, output)} ${transformer.outputClauseVariableName(drgElement, output)}) {
        this.${transformer.outputClauseVariableName(drgElement, output)} = ${transformer.outputClauseVariableName(drgElement, output)};
    }
    <#if modelRepository.isOutputOrderHit(expression.hitPolicy)>

    public Integer ${transformer.priorityGetter(drgElement, output)} {
        return this.${transformer.outputClausePriorityVariableName(drgElement, output)};
    }
    public void ${transformer.prioritySetter(drgElement, output)}(Integer ${transformer.outputClausePriorityVariableName(drgElement, output)}) {
        this.${transformer.outputClausePriorityVariableName(drgElement, output)} = ${transformer.outputClausePriorityVariableName(drgElement, output)};
    }
    
    


<#macro addEqualsAndHashCode itemDefinition >
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ${javaClassName} other = (${javaClassName}) o;
        <#assign expression = modelRepository.expression(drgElement)>
        <#list expression.output as output>
            <#assign member = transformer.getter(drgElement, output)/>
        if (this.${member} != null ? !this.${member}.equals(other.${member}) : other.${member} != null) return false;
            <#if modelRepository.isOutputOrderHit(expression.hitPolicy)>
                <#assign member = transformer.priorityGetter(drgElement, output)/>
        if (this.${member} != null ? !this.${member}.equals(other.${member}) : other.${member} != null) return false;
            
        

        return true;
    }

    @Override
    public int hashCode() {
        int result = 0;
        <#assign expression = modelRepository.expression(drgElement)>
        <#list expression.output as output>
            <#assign member = transformer.getter(drgElement, output)/>
        result = 31 * result + (this.${member} != null ? this.${member}.hashCode() : 0);
            <#if modelRepository.isOutputOrderHit(expression.hitPolicy)>
                <#assign member = transformer.priorityGetter(drgElement, output)/>
        result = 31 * result + (this.${member} != null ? this.${member}.hashCode() : 0);
            
        

        return result;
    }


<#macro addSortMethod drgElement>
    <#assign expression = modelRepository.expression(drgElement)>
    <#if modelRepository.isOutputOrderHit(expression.hitPolicy)>

    @Override
    public List<${transformer.abstractRuleOutputClassName()}> sort(List<${transformer.abstractRuleOutputClassName()}> matchedResults_) {
    <#list expression.output as output>
        List<${transformer.pairClassName()}<${transformer.outputClauseClassName(drgElement, output)}, Integer>> ${transformer.outputClauseVariableName(drgElement, output)}Pairs = new ArrayList<>();
        matchedResults_.forEach(matchedResult_ -> {
            ${transformer.outputClauseVariableName(drgElement, output)}Pairs.add(new ${transformer.pairClassName()}(((${javaClassName})matchedResult_).${transformer.getter(drgElement, output)}, ((${javaClassName})matchedResult_).${transformer.priorityGetter(drgElement, output)}));
        });
        ${transformer.outputClauseVariableName(drgElement, output)}Pairs.sort(new ${transformer.pairComparatorClassName()}());
    

        List<${transformer.abstractRuleOutputClassName()}> result_ = new ArrayList<${transformer.abstractRuleOutputClassName()}>();
        for(int i=0; i
            output_.${transformer.setter(drgElement, output)}(${transformer.outputClauseVariableName(drgElement, output)}Pairs.get(i).getLeft());
            output_.${transformer.prioritySetter(drgElement, output)}(${transformer.outputClauseVariableName(drgElement, output)}Pairs.get(i).getRight());
            
            result_.add(output_);
        }
        return result_;
    }
    


<#macro addToString drgElement>
    public String toString() {
        StringBuilder result_ = new StringBuilder("(matched=" + isMatched());
        <#list expression.output as output>
        <#assign member = transformer.outputClauseVariableName(drgElement, output)/>
        result_.append(String.format(", ${member}='%s'", ${member}));
        
        result_.append(")");
        return result_.toString();
    }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy