Skip to content

fairjm/common-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Common Rules

A groovy script based common rule engine for java.
Just a toy.Use linear search so the performance is really bad when handling hundreds of rules with thousands of fact.

What is Common Rules?

common rules is just a simple groovy script based rule engine(maybe a wrapper is more proper :>)
As the name common says, it uses map as fact input and groovy script as rule content to meet common rule engine usage.

Usage Scenario

It fits the situation that you just want to write some dynamic rules to your DB, load and execute it in you code.
All you need to do is writing groovy script(or you can just use java syntax, thx for the great compatible) and use map as fact.

How to Use?

just write simple groovy script as the content of rule.

// use map as fact
final Map<String, Object> fact = new HashMap<>();
		fact.put("age", 18);
		fact.put("name", "cc");
		fact.put("male?", true);
		fact.put("favors", Arrays.asList("coding", "sleeping"));
// write a rule
final CommonRule rule1 = CommonRuleFactory
				.build("ccFactRule",
						"fact['age'] < 19 && fact['name'] == 'cc' && 'coding' in fact['favors'] && fact['male?'] ")
				.get();
// then test
assertTrue(CommonRuleEngine.match(rule1, fact));

About

A groovy script based common rule engine for java.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages