<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi Wolfgang,</DIV>
<DIV>&nbsp;</DIV>
<DIV>thanks for your reply.</DIV>
<DIV>I did have the idea about having the concepts of first, last,predecessor, successor&nbsp;etc. in TimeEntry. Unfortunately, it really isn't possible because this class&nbsp;(i.e TimeEntry) is a main part of a huge application model, which has been existing since long, has many dependencies to other classes, and shouldn't be changed ("only" for fulfilling the requirement of rules-engine) . So unfortunately I&nbsp;can only&nbsp;use those which are available to me. That's why I was hoping if there's really pure rule-based solution to this.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards</DIV>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><BR>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 13px"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Wolfgang Laun &lt;wolfgang.laun@gmail.com&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Rules Users List &lt;rules-users@lists.jboss.org&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Wed, November 11, 2009 11:29:29 AM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [rules-users] Need help in formulating rule (using list)<BR></FONT><BR>Implied by the List representation are concepts such as "first",<BR>"last", "predecessor"<BR>and "successor". All of these may or may not be represented by the fields in<BR>TimeEntry. This would be so if it is *guaranteed* that one TimeEntry's<BR>start time is another one's end time; (and then you wouldn't even need them<BR>being sorted). Failing this, an explicit representation by adding an ordinal<BR>number or (as I prefer doing) a reference to the previous and next TimeEntry<BR>might be considered.<BR><BR>But, either way, reasoning
 over pairs of TimeEntry objects (of one<BR>Schedule) requires that they are all (at least temporarily) present as facts in<BR>WM. Then, to be identified as TimeEntrys of a specific Schedule, they also<BR>could have a reference to that.<BR><BR>It's a simple task to write a rule that fires for a new Schedule and creates<BR>the extended TimeEntryPlus facts from its List&lt;TimeEntry&gt;. To avoid NPEs,<BR>I'd add a dummy TimeEntryPlus object (type=="OFF") before and after. Then, you<BR>could write rules<BR><BR>rule checkValidBreak1<BR>when<BR>&nbsp; &nbsp; $break : TimeEntryPlus( type == "BREAK" )<BR>&nbsp; &nbsp; TimeEntryPlus( type == "WORK", succ == $break || pred == $break,<BR>length &lt;= 10 )<BR>then<BR>&nbsp; System.out.println( "Short work b/a break " + ... $break ...,<BR>$break.getSchedule() ... )<BR>end<BR><BR>rule checkValidBreak2<BR>when<BR>&nbsp; &nbsp; $break : TimeEntryPlus( type == "BREAK" )<BR>&nbsp; &nbsp; TimeEntryPlus( type == "WORK",
 succ == $break )<BR>then<BR>&nbsp; System.out.println( "Can't start with a break " + ... $break ...,<BR>$break.getSchedule() ... )<BR>end<BR><BR>-W<BR><BR><BR>On Wed, Nov 11, 2009 at 10:46 AM, psentosa &lt;<A href="mailto:psentosa@yahoo.com" ymailto="mailto:psentosa@yahoo.com">psentosa@yahoo.com</A>&gt; wrote:<BR>&gt;<BR>&gt; Hi Brody,<BR>&gt;<BR>&gt; I have had similar situation several times, and each time I had to modify my<BR>&gt; objects to avoid this, and it was really tedious.<BR>&gt; I'd also would like to know whether it is possible to have a "real solution"<BR>&gt; in this case without needing to change the base objects, but rather use the<BR>&gt; rule language to formulate this kind of business rule<BR>&gt;<BR>&gt; *why didn't I receive this mail through the mailing list? maybe you haven't<BR>&gt; subscribed yet?*<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; Brody bach wrote:<BR>&gt;&gt;<BR>&gt;&gt; Hi all,<BR>&gt;&gt;<BR>&gt;&gt; I have an object
 which I use as main fact object, let's say "Schedule",<BR>&gt;&gt; which has a list of objects called "TimeEntry" &nbsp;---&gt;<BR>&gt;&gt;<BR>&gt;&gt; class Schedule(){<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;List&lt;TimeEntry&gt; entries;<BR>&gt;&gt; }<BR>&gt;&gt;<BR>&gt;&gt; class TimeEntry(){<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;String type;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;Date start;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;Date end;<BR>&gt;&gt; &nbsp; &nbsp; &nbsp;Integer length;<BR>&gt;&gt; }<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; Now, if I insert Schedule into the WM, and would like to iterate over the<BR>&gt;&gt; list of TimeEntry, due to the following business rule :<BR>&gt;&gt;<BR>&gt;&gt; For all time entries, if it is of type BREAK:<BR>&gt;&gt; check whether a time entry of type WORK exist,<BR>&gt;&gt; before and/or after this BREAK, which has only length of 10 minutes<BR>&gt;&gt;<BR>&gt;&gt; The content of the time entry list has been sorted before so they are
 all<BR>&gt;&gt; in correct time order, e.g<BR>&gt;&gt;<BR>&gt;&gt; 09:00 - 09:10 &nbsp;WORK (10 min)<BR>&gt;&gt; 09:10 - 09:30 &nbsp;BREAK (20 min)<BR>&gt;&gt; 09:30 - 10:30 &nbsp;WORK &nbsp;(60 min)<BR>&gt;&gt; --&gt; in this case, the rule should fire<BR>&gt;&gt;<BR>&gt;&gt; How can I define this rule? Some questions which I have:<BR>&gt;&gt; - how do I check previous and next element of the current element?<BR>&gt;&gt; - the length of the list isn't fix; it may contain 1, 2, or more entries.<BR>&gt;&gt; So somehow in an attempt to access next element, it should take care of<BR>&gt;&gt; the bound of the list. But should this be really part of the rule<BR>&gt;&gt; definition?<BR>&gt;&gt;<BR>&gt;&gt; Many thanks in advance!<BR>&gt;&gt;<BR>&gt;&gt; Regards<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;<BR>&gt; --<BR>&gt; View this message in context:
 http://old.nabble.com/Need-help-in-formulating-rule-%28using-list%29-tp26284362p26298480.html<BR>&gt; Sent from the drools - user mailing list archive at <A href="http://nabble.com/" target=_blank>Nabble.com</A>.<BR>&gt;<BR>&gt; _______________________________________________<BR>&gt; rules-users mailing list<BR>&gt; <A href="mailto:rules-users@lists.jboss.org" ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR>&gt; <A href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>&gt;<BR><BR>_______________________________________________<BR>rules-users mailing list<BR><A href="mailto:rules-users@lists.jboss.org" ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR></DIV></DIV><!--
 cg8.c4.mail.gq1.yahoo.com compressed/chunked Tue Nov 10 06:41:49 PST 2009 --></div><br>



      </body></html>