public OclBag flattenToBag() { List <OclAny> list = new List <OclAny>(); FlattenToList(list, OclCollectionType.Depth(elementType)); return(new OclBag(OclCollectionType.BasicElementType(elementType), list)); }
public OclSequence flattenToSequence() { OclSequence seq = new OclSequence(OclCollectionType.BasicElementType(elementType)); FlattenToList(seq.list, OclCollectionType.Depth(elementType)); return(seq); }
private static void ClosureTo <T>(OclClassifier newElementType, IEnumerable <OclAny> source, ICollection <OclAny> dst, Func <T, OclAny> body) where T : OclAny { //Iterate over added items foreach (OclAny s in source) { //Do not add duplicates if (!dst.Contains(s)) { dst.Add(s); //Execute body for newly added item OclAny newItems = body((T)s); //Ignore null if (!IsNull(newItems)) { OclClassifier type = newItems.oclType(); if (type.ConformsToInternal(OclCollectionType.Collection(OclAny.Type))) { //Collection must be of new element type if (type.ConformsToInternal(OclCollectionType.Collection(newElementType))) { ClosureTo(newElementType, (OclCollection)newItems, dst, body); } else { throw new InvalidCastException(); } } else { //Non-collection must be kind of new element type if (type.ConformsToInternal(newElementType)) { //Add the result OclAny[] arr = { newItems }; ClosureTo(newElementType, arr, dst, body); } else { throw new InvalidCastException(); } } } } } }
public override OclClassifier oclType() { return(OclCollectionType.Collection(OclCollectionKind.Bag, elementType)); }