Page last modified 17:11, 11 Jan 2016 by Antero

asBag, asSet, asOrderedSet, asSequence

    Table of contents

    Description of the method

     

    Description:

    Methods asBag, asSet, asOrderedSet and asSequence create a collection of the specified type.

    Please note the usage in collections wiki page.

    • Bag - no order, may contain duplicates
    • Set - no order, duplicates removed   
    • OrderedSet - ordered, duplicates removed
    • Sequence - ordered, may contain duplicates  

     

     

    Available for:

    base64binary, boolean, datetime, double/decimal, date, hexBinary, integer, string, double/decimal and integer

    Parameters: -
    Return type: -

    Example1

     

    Context: Message
    OCL: self.Header.ControlSum =
    self.Transaction->asBag().Amount->sum()


     

    Description: Compares the value of ControlSum against the sum of values in Transaction, which is defined to be in collection type bag.

     

    The XML snippet below would pass this check. Note the second occurrence of transaction, expression is true because amount is not above 200.

    <?xml version="1.0" encoding="UTF-8"?>
    <Message xmlns="http://www.XMLdation.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Header>
        <Id>a</Id>
        <TimeStamp>2015-07-03T12:17:50</TimeStamp>
        <ControlSum>2</ControlSum>
        <NumberOfTransactions>1</NumberOfTransactions>
      </Header>
      <Transaction>
        <Id>TransactionId1</Id>
        <Amount>1</Amount>
        <Debtor>
          <Name>Debtor1</Name>
        </Debtor>
        <Creditor>
          <Name>Creditor1</Name>
        </Creditor>
      </Transaction>
      <Transaction>
        <Id>TransactionId2</Id>
        <Amount>1</Amount>
        <Debtor>
          <Name>Debtor2</Name>
        </Debtor>
        <Creditor>
          <Name>Creditor2</Name>
        </Creditor>
      </Transaction>
    </Message>

    The other snippet below however would not pass

    <ControlSum>4</ControlSum>

    (with everything else similar than in the valid file)

    Menu