⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rhsbuilder.java

📁 jboss规则引擎
💻 JAVA
字号:
package org.drools.decisiontable.parser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.drools.decisiontable.model.SnippetBuilder;

/**
 * Builds up a consequence entry.
 * @author Michael Neale
 *
 */
public class RhsBuilder implements SourceBuilder {

    private Map     templates;
    private String  variable;
    private List    values;
    private boolean hasValues;

    /**
     * @param boundVariable Pass in a bound variable if there is one.
     * Any cells below then will be called as methods on it. 
     * Leaving it blank will make it work in "classic" mode.
     */
    public RhsBuilder(String boundVariable) {
        this.variable = boundVariable == null ? "" : boundVariable.trim();
        this.templates = new HashMap();
        this.values = new ArrayList();
    }

    public void addTemplate(int col,
                                       String content) {
        Integer key = new Integer( col );
        content = content.trim();
        if ( isBoundVar() ) {
            content = variable + "." + content + ";";
        }
        this.templates.put( key,
                            content );
    }

    private boolean isBoundVar() {
        return !("".equals( variable ));
    }

    public void addCellValue(int col,
                             String value) {
        hasValues = true;
        String template = (String) this.templates.get( new Integer( col ) );
        SnippetBuilder snip = new SnippetBuilder(template);
        
        this.values.add(snip.build( value ));

    }
    
    public void clearValues() {
        this.hasValues = false;
        this.values.clear();
    }
    
    public String getResult() {
        StringBuffer buf = new StringBuffer();
        for ( Iterator iter = this.values.iterator(); iter.hasNext(); ) {            
            buf.append( iter.next() );
            if (iter.hasNext()) {
                buf.append( '\n' );
            }
        }
        return buf.toString();
    }

    public boolean hasValues() {
        
        return hasValues;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -