singleitem

Dieser Ausdruck ruft einen einzelnen Eintrag aus einer Liste ab.

Der Ausdruck singleitem kann nützlich sein, wenn erwartet wird, dass eine Liste nur einen einzigen Eintrag enthält, beispielsweise beim Filtern einer Liste nach Bedingungen, die lediglich einen einzigen Eintrag in der Liste auswählen sollten.

Der Ausdruck singleitem gibt Folgendes an:

Informationen zum Abrufen eines Eintrags an einer bestimmten Position in einer Liste enthalten die Angaben über get in Nützliche Listenoperationen.

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

    <Attribute name="dateOfBirth">
      <type>
        <javaclass name="curam.util.type.Date"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

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

    <!-- The first child born to this person -->
    <Attribute name="firstBornChild">
      <type>
        <ruleclass name="Person"/>
      </type>
      <derivation>
        <!-- get the first child, if any
             - if no children, return null -->
        <singleitem onEmpty="returnNull" onMultiple="returnFirst">
          <!-- sort the children in date-of-birth order -->
          <sort>
            <list alias="child">
              <reference attribute="children"/>
            </list>
            <sortorder>
              <sortitem direction="ascending">
                <reference attribute="dateOfBirth">
                  <current alias="child"/>
                </reference>
              </sortitem>
            </sortorder>
          </sort>

        </singleitem>
      </derivation>

    </Attribute>

    <!-- Retrieve the single household information record
         from external storage - there should always
         be exactly one - anything else is an error.  -->
    <Attribute name="householdInformation">
      <type>
        <ruleclass name="HouseholdInformation"/>
      </type>
      <derivation>
        <singleitem onEmpty="error" onMultiple="error">
          <readall ruleclass="HouseholdInformation"/>
        </singleitem>
      </derivation>
    </Attribute>

  </Class>

  <Class name="HouseholdInformation">

    <Attribute name="householdContainsDisabledPerson">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>