sort

Creates a new list by sorting the members of an existing list according to a specified sort order.

A sort expression specifies:

The sortorder specifies one or more sortitem s, each of which specifies the item to sort by and whether to sort in ascending or descending order.

The sortitem s are listed most-significant first; each sortitem is only evaluated if two items being sorted are identical with regard to more significant sortitem s.

Within each sortitem, you can use current to refer to the list item being sorted. Typically each sortitem will refer to some attribute or calculation on the current list item.

If two (or more) items in the list are identical with regard to all the sortitem s, then they are returned in the same relative order as the source list.

The behavior of the sort expression is similar to SQL's ORDER BY clause.

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

    <Attribute name="members">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- Arranges the members in order of age (oldest to youngest);
         for members which are the same age, the members are
         arranged in alphabetical order by first name. -->
    <Attribute name="sortedMembers">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <sort>
          <list>
            <reference attribute="members"/>
          </list>
          <sortorder>
            <sortitem direction="descending">
              <!-- The age of the person in the list -->
              <reference attribute="age">
                <current/>
              </reference>
            </sortitem>
            <!-- The first name of the person in the list -->
            <sortitem direction="ascending">
              <reference attribute="firstName">
                <current/>
              </reference>
            </sortitem>
          </sortorder>
        </sort>
      </derivation>
    </Attribute>

  </Class>

  <Class name="Person">

    <Initialization>
      <Attribute name="firstName">
        <type>
          <javaclass name="String"/>
        </type>
      </Attribute>
      <Attribute name="age">
        <type>
          <javaclass name="Integer"/>
        </type>
      </Attribute>
    </Initialization>

  </Class>

</RuleSet>