Hi Michal.

This is really a basic Java programming question, I think. Using Java, you can iterate over the elements of the first ArrayList to ensure they are contained in the second ArrayList. Assume that the first list is contained in the second and seek evidence to the contrary:

boolean contained = true;
for (int i = 0; i < list1.size(); ++i)  {
   if (list2.contains(list1.get(i)) == false) {contained = false; break;}
}

This also works if there are duplicates in either list. You should also decide how you want to treat empty lists (i.e., should they be contained in any list, as in the code above).

In Jess there are various approaches to use. For example, you can use (intersection$ ?list1 ?list2) and the compare the size of the intersection to the size of the ?list1. If they're the same, then ?list1 is contained in ?list2:

deffunction is-first-list-contained-in-second-list (?list1 ?list2)
 (eq (length$ (intersection$ ?list1 ?list2)) (length$ ?list1)))

The same points as in the Java code above: This also works if there are duplicates in either list. You should also decide how you want to treat empty lists (i.e., should they be contained in any list, as in the code above).

Regards,

Win

Micha? Horzela wrote:
Hi,

How to compare that one list of object contains all objects from other list in Jess ?

How to obtain inside jess (in Jess source file: clp)
two list of objects (java.util.ArrayList) as two separate facts ?


I have 2 lists of objects of the same class.

My rule must check if all objects from first list exists in second list
(if second list contains all objects from first list)

Example:

In first I have for example 2 objects (of class TestData)
and in second list I have 3 objects = the same 2 objects as in first list and one other object.
Rule for this case should be fulfilled.



           public class TestData {
               private String name;
               private Integer id;
                         public TestData(Integer id,String name) {
                   this.name = name;
                   this.id = id;
               }
                         ...//getters and setters
           }
                                                   ....
           List<TestData> list1 = new ArrayList<TestData>();
           List<TestData> list2 = new ArrayList<TestData>();
           list1.add( new TestData(1,"test a"));
           list1.add( new TestData(1,"test b"));
           list2.addAll(list1);
           list2.add( new TestData(1,"test c"));
System.out.println("__java check__:" + list2.containsAll(list1)); //this will be: TRUE
                     this.engine.add( list1 );
           this.engine.add( list2 );
                     ...
           this.engine.run()
           ....


thanks for any answer
and sorry for my english


Michal




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------


begin:vcard
fn:Win Carus
n:Carus;Win
org:Information Extraction Systems, Inc.
adr:;;20 East Quinobequin Road;Waban;MA;02468;USA
email;internet:[EMAIL PROTECTED]
title:President
tel;work:(617) 244-5068
tel;fax:(617) 244-5068
x-mozilla-html:FALSE
url:http://www.InfoExtract.com
version:2.1
end:vcard

Reply via email to