示例#1
0
文件: OclBag.cs 项目: mff-uk/exolutio
        public OclBag flattenToBag()
        {
            List <OclAny> list = new List <OclAny>();

            FlattenToList(list, OclCollectionType.Depth(elementType));
            return(new OclBag(OclCollectionType.BasicElementType(elementType), list));
        }
示例#2
0
        public OclSequence flattenToSequence()
        {
            OclSequence seq = new OclSequence(OclCollectionType.BasicElementType(elementType));

            FlattenToList(seq.list, OclCollectionType.Depth(elementType));
            return(seq);
        }
示例#3
0
 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();
                     }
                 }
             }
         }
     }
 }
示例#4
0
文件: OclBag.cs 项目: mff-uk/exolutio
 public override OclClassifier oclType()
 {
     return(OclCollectionType.Collection(OclCollectionKind.Bag, elementType));
 }