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:
Das Verhalten, wenn festgestellt wird, dass die Liste leer ist. Möglich sind folgende Angaben:
Ein Laufzeitfehler tritt auf (verwenden Sie diese Option, wenn erwartet wird, dass die Liste nicht leer ist).
Der Wert null wird zurückgegeben.
Das Verhalten, wenn festgestellt wird, dass die Liste mehrere Einträge enthält. Möglich sind folgende Angaben:
Ein Laufzeitfehler tritt auf (verwenden Sie diese Option, wenn nicht erwartet wird, dass die Liste mehrere Einträge enthält).
Der Wert null wird zurückgegeben.
Der erste Eintrag in der Liste wird zurückgegeben.
Der letzte Eintrag in der Liste wird zurückgegeben.
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>