Skip to content

Instantly share code, notes, and snippets.

@mill5james
Last active April 20, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mill5james/367202b9d50d4353e4aae8778598c9f9 to your computer and use it in GitHub Desktop.
Save mill5james/367202b9d50d4353e4aae8778598c9f9 to your computer and use it in GitHub Desktop.
Rulebook problem
import com.deliveredtechnologies.rulebook.Fact;
import com.deliveredtechnologies.rulebook.FactMap;
import com.deliveredtechnologies.rulebook.NameValueReferableMap;
import com.deliveredtechnologies.rulebook.model.runner.RuleBookRunner;
public class App {
public static void main(String[] args) {
RuleBookRunner rules = new RuleBookRunner("rules");
NameValueReferableMap<String> facts = new FactMap<>();
facts.put("key", new Fact<>("value"));
rules.run(facts);
}
}
package rules;
import com.deliveredtechnologies.rulebook.RuleState;
import com.deliveredtechnologies.rulebook.annotation.Given;
import com.deliveredtechnologies.rulebook.annotation.Rule;
import com.deliveredtechnologies.rulebook.annotation.Then;
import com.deliveredtechnologies.rulebook.annotation.When;
@Rule(order = 1)
public class ReturnsNext {
@Given("key")
String value;
@When
public boolean when() { return true; }
@Then
public RuleState then() { return RuleState.NEXT; }
}
package rules;
import com.deliveredtechnologies.rulebook.RuleState;
import com.deliveredtechnologies.rulebook.annotation.Given;
import com.deliveredtechnologies.rulebook.annotation.Rule;
import com.deliveredtechnologies.rulebook.annotation.Then;
import com.deliveredtechnologies.rulebook.annotation.When;
@Rule(order = 2)
public class SimpleRule {
@Given("key")
String value;
@When
public boolean when() { return true; }
@Then
public RuleState then() { return RuleState.BREAK; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment