RE: collections with one element only



Date view Thread view Subject view Author view Attachment view

From: Richard Mitchell (richard@inferdata.com)
Date: Tue 20 Jan 2004 - 14:43:57 GMT


Hi Hans,

We've used OCL's any() to do this job, on the assumption that, if the
collection contains exactly one element it's clear what is returned (though
it might not be clear to readers what you are trying to say, which is a
different issue :-)

Best wishes,
-- Richard

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Richard Mitchell

InferData Ltd
3D: Domain-Driven Development
Consulting, Training, Mentoring

richard@inferdata.com
www.inferdata.com

"By itself, logic says nothing about anything ..."


> -----Original Message-----
> From: puml-list-request@cs.york.ac.uk
> [mailto:puml-list-request@cs.york.ac.uk]On Behalf Of SainTiss
> Sent: 20 January 2004 13:56
> To: puml-list@cs.york.ac.uk
> Subject: collections with one element only
>
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> Is there a way to treat a collection with one element as if it were the
> element itself?
>
> Suppose the collection is a bag, then I guess one could do this:
> bag->asSequence->first
> But that's not too elegant. Is there a more elegant way?
>
> For example: suppose a certain to-many association should contain
> exactly one
> element in a certain case, and then there are additional
> constraints on that
> element. Is the only possible way to specify this something like the
> following?
>
> obj.myToManyAssoc->size = 1 and
> obj.myToManyAssoc->asSequence->first.name =
> "name"
>
> maybe using "forAll" on the collection is shorter already, but it still
> implies working with a collection...
>
> Thanks in advance,
>
> Hans Schippers
>
> - --
> Ark Linux - Linux for the Masses (http://arklinux.org)
>
> Capitalism:
> You don't have any cows. The bank will not lend you money to buy cows,
> because you don't have any cows to put up as collateral.
>
> Representative Democracy:
> You have two cows. Your neighbors pick someone to tell you who
> gets the milk.
>
> In a world without walls and fences, who needs windows and gates?
>
> Hans Schippers
> 2LIC INF
> UA 2003-2004
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFADTNzXlnUYIbmLOQRAvD5AJ40FwnmyB9Ic3CLkL3WKE3JEMZtnACfd6D/
> g7dXXYZCoGQ1WsaQeZqzLdo=
> =Qorb
> -----END PGP SIGNATURE-----
>
>
>
>
> To remove yourself from this list please mail
> puml-list-request@cs.york.ac.uk
> with a message containing the word "unsubscribe".
>

Date view Thread view Subject view Author view Attachment view