Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to apply rule for each object in a list in one session and return the result from action? #408

Open
ashwiniakshay04 opened this issue Jan 18, 2023 · 1 comment

Comments

@ashwiniakshay04
Copy link

As far as I can tell, we can fire multiple facts at once, and the rules that match the fact's value will be executed. What if we want to evaluate multiple objects representing the same fact?

We cannot enter two facts with the same key because the Facts object is a hashmap. So I'm thinking we can make lists for each object type and then apply the rules to each object in the list. But how can rules be applied to each object in that list, where the list is a fact?

List dataBall = new ArrayList<>();
dataBall.add(new Ball("Red", 7, "B"));
dataBall.add(new Ball("Blue", 3, "A"));

List dataBat = new ArrayList<>();
dataBat.add(new Bat("Green", 8, "B"));
dataBat.add(new Bat("Red", 5, "A"));
dataBat.add(new Bat("Green", 6, "B"));

Facts fact = new Facts();
fact.put("ball", dataBall);
fact.put("bat", dataBat);

I want to execute two different rules based on the facts. As an example: For the fact "ball," I'd like to run the ball rule for each ball in the dataBall list. Similarly, for bat. All of this in one execution/ fire.

@Siktik
Copy link

Siktik commented Jul 22, 2024

hey, the way i can think of achieving this is by implementing a method for both the dataBall and the dataBat class with the same name, which returns a bool. in fact.put() you should use the same name for both classes, f.e. "myClass". you can then call this method in the condition where you check which class is calling an evaluate according to this. For the action u also define a method on the class level where you can implement anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants