Description of the method
Description: | ->sum() method returns the sum of all the elements in the container that supports the "+"-operation, e.g. integer. |
Available for: | integer, real |
Parameters: | - |
Return type: | integer, real |
Example
Context: | Message |
OCL: | self.Transaction.Amount->sum() = 100 |
Description: | The example sums every transaction amount in the message if the amounts are valid type and compares them to the integer. If the sum is 100, true will be returned. |
The XML snippet below would pass this check.
<?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>2018-05-28T12:17:50</TimeStamp>
<ControlSum>2</ControlSum>
<NumberOfTransactions>1</NumberOfTransactions>
</Header>
<Transaction>
<Id>TransactionId1</Id>
<Amount>50</Amount>
<Debtor>
<Name>Debtor1</Name>
</Debtor>
<Creditor>
<Name>Creditor1</Name>
</Creditor>
</Transaction>
<Transaction>
<Id>TransactionId2</Id>
<Amount>50</Amount>
<Debtor>
<Name>Debtor2</Name>
</Debtor>
<Creditor>
<Name>Creditor2</Name>
</Creditor>
</Transaction>
</Message>
The other snippet below however would not pass this check. (The sum of transaction amounts is more than 100)
<?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>2018-05-28T12:17:50</TimeStamp>
<ControlSum>2</ControlSum>
<NumberOfTransactions>1</NumberOfTransactions>
</Header>
<Transaction>
<Id>TransactionId1</Id>
<Amount>100</Amount>
<Debtor>
<Name>Debtor1</Name>
</Debtor>
<Creditor>
<Name>Creditor1</Name>
</Creditor>
</Transaction>
<Transaction>
<Id>TransactionId2</Id>
<Amount>50</Amount>
<Debtor>
<Name>Debtor2</Name>
</Debtor>
<Creditor>
<Name>Creditor2</Name>
</Creditor>
</Transaction>
</Message>