filter

Creates a new list containing all the items in an existing list which meet the filter condition.

The filter expression contains:

Typically the listitemexpression contains one or more calculations applied to the current item in the list.

The relative order of the list items in the filtered result will preserve the relative order of the list items in the original list. If none of the items in the list meet the filter condition, then an empty list is returned.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_filter"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <Attribute name="age">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- The spouse of this person, or
      null if unmarried -->
    <Attribute name="spouse">
      <type>
        <ruleclass name="Person"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- The children of this person -->
    <Attribute name="children">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>



  </Class>



  <Class name="Household">

    <!-- All the people in the household -->
    <Attribute name="members">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- All the adults in the household -->
    <Attribute name="adultMembers">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <reference attribute="members"/>
          </list>
          <listitemexpression>
            <compare comparison=">=">
              <reference attribute="age">
                <current/>
              </reference>
              <Number value="18"/>
            </compare>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>

    <!-- All the lone parents in the household -->
    <Attribute name="loneParents">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <reference attribute="members"/>
          </list>
          <listitemexpression>
            <all>
              <fixedlist>
                <listof>
                  <javaclass name="Boolean"/>
                </listof>
                <members>

                  <!-- No spouse -->
                  <equals>
                    <reference attribute="spouse">
                      <current/>
                    </reference>
                    <null/>
                  </equals>
                  <!-- At least one child -->
                  <not>
                    <property name="isEmpty">
                      <object>
                        <reference attribute="children">
                          <current/>
                        </reference>
                      </object>
                    </property>
                  </not>
                </members>
              </fixedlist>
            </all>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>