3

Check if an object in a list has a certain value with drools

 2 years ago
source link: https://www.codesd.com/item/check-if-an-object-in-a-list-has-a-certain-value-with-drools.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Check if an object in a list has a certain value with drools

advertisements

I have some problems checking if an object of a list has a value with drools.

My model is this

class Products{
    private List<Approver> approvalPath;
}
class Approver{
    private String employeeName;
}

So, I need to make a rule like this

rule "member"
    when
        //approvalPath has an approver with name "Charles" (for example)
    then
        //do something
end

How can I do it?


Here are two versions.

when
  $app: Approver( employeeName == "Charles" )
  Products( approvalPath contains $pp )

when
  Products( $ap: approvalPath )
  Approver( employeeName == "Charles" ) from $ap

Number 1 requires the insertion of Approver objects as facts.

Related Articles

Store in a variable the number of rows in a table where a column has a certain value in SQL Server Compact

I have a Windows Forms application and a SQL Server Compact 3.5 database. I want to store in a variable the number of rows from a table where a column has a certain value. I have something like this to count all the rows from a table: CarsDataSet car

Sorting two-dimensional lists of a certain value

I read an answer to a question on here but I can't find it now. It was how to sort a two-dimensional list by a certain value. I know it was ListName.sort() (ListName is what the name of the list would be when I put the list's name in instead when I e

Check if a string in a list contains a specific string with Linq

I have a List<string> that has some items like this: {"Pre Mdd LH", "Post Mdd LH", "Pre Mdd LL", "Post Mdd LL"} Now I want to perform a condition that checks if an item in the list contains a specific string.

Set the field of objects in the list to the same value and return a list

I have a function that returns a list of Objects. After getting that list, I want to set a field in each of these objects to an identical value. Is there a way with which I could reduce the three (mock) lines of code below to one? List<someObjects>

Java 8 Stream adds a new object to the list from the return value

I want to save the return value of a method and use it to create a new object with which ill add to a list. Here is the block of code for more clarity: final List<FooBoo> fooboos = new ArrayList<>(); for (Foo foo : foos) { Optional<Boo>

Using linq or otherwise, how does it check if all items in the list have the same value and return or return a "different title" if they do not?

If all the items in a list have the same value, I need to use that value, otherwise I need to use an "otherValue". I can't think of a simple and clear way of doing this. see also Neat way to write loop that has special logic for the first item i

Haskell: modifies all the indices of a list to a certain value

If I am given a list of objects and another list for some indices from this list, is there an easy way to change every object in this list with an index from the list of indices to a different value? E.g. I am hoping there exists some function f such

How to create a 2D Python list based on certain values ​​in a list

I have a list of the following values: numbers = [127, 127, 0, 1, 1, 1, 4, 14, 127, 0, 1, 1, 1, 3, 8, 4, 14, 127, 0, 1, 1, 1, 4, 14, 127, 0, 1, 1, 1, 3, 8, 4, 14, 127, 0, 1, 1, 1, 3, 8, 4, 14, 127, 0, 1, 1, 1, 4, 14, 127, 0, 1, 1, 1, 4, 14, 127, 0, 1

Delete a dictionary key that has a certain value

This question already has an answer here: Removing entries from a dictionary based on values 4 answers I know dictionary's are not meant to be used this way, so there is no built in function to help do this, but I need to delete every entry in my dic

Show the text box only when it has a certain value

I have Ajax page where I get search response inside textarea. Here is the code <form onSubmit="checkDomain();return false;" id="ajaxDomainForm" action=""> <input name="domain" type="text" id="

List iteration & amp; Set Values ​​with Java 8 Streams API

I'm trying to understand how to use the Java 8 Streams API. For example, I have these two classes: public class User { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } public class

How to divide a list to a certain value

given a unique valued list such as [5,4,9,2,1,7,'dog',9] is there a way to split it a a certain value? ie [5,4,9,2,7,'dog'].split(4) = [5,4],[9,2,7,'dog'] [5,4,9,2,7,'dog'].split(2) = [5,4,9,2], [7,'dog'] ? >>> mylist = [5,4,9,2,7,'dog'] >>

Can I use LINQ to check if the objects in a list have a unique ID?

say I have a list containing objects like this one: public class Person { private string _name; private string _id; private int _age; public Person { } // Accessors } public class ManipulatePerson { Person person = new Person(); List<Person> personL

C # - How to check if an object of a type has to be built?

(I'm sorry if duplicate, I'm not sure if to check for nullable or for primitives or whatever) I'm creating arrays of objects of a variable Type. It can be int, string, Point or MyCustomClass (probably no enums though, but they are same as int right ?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK