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

📄 golfingexample.java

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

import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;

public class GolfingExample {

    /**
     * @param args
     */
    public static void main(final String[] args) throws Exception {

        final PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl( new InputStreamReader( GolfingExample.class.getResourceAsStream( "golf.drl" ) ) );

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( builder.getPackage() );

        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
        
        String[] names = new String[] { "Fred", "Joe", "Bob", "Tom" };
        String[] colors = new String[] { "red", "blue", "plaid", "orange" };
        int[] positions = new int[] { 1, 2, 3, 4 };
        
        for ( int n = 0; n < names.length; n++ ) {
            for ( int c = 0; c < colors.length; c++ ) {
                for ( int p = 0; p < positions.length; p++ ) {
                    workingMemory.assertObject( new Golfer( names[n], colors[c], positions[p]) );
                }                
            }            
        }

        workingMemory.fireAllRules(); 
    }


    public static class Golfer {
        private String name;
        private String color;
        private int position;
        
        public Golfer(String name,
                      String color,
                      int position) {
            super();
            this.name = name;
            this.color = color;
            this.position = position;
        }
        /**
         * @return the color
         */
        public String getColor() {
            return this.color;
        }
        /**
         * @return the name
         */
        public String getName() {
            return this.name;
        }
        
        /**
         * @return the name
         */
        public int getPosition() {
            return this.position;
        }        
        
    }
}

⌨️ 快捷键说明

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