Beispiel #1
0
        public OclSequence append <T>(OclClassifier newElementType, T item) where T : OclAny
        {
            OclSequence newList = new OclSequence(newElementType, list);

            newList.list.Add(item);
            return(newList);
        }
Beispiel #2
0
        public OclSet union(OclClassifier newElementType, OclSet s2)
        {
            OclSet newSet = new OclSet(newElementType, set);

            newSet.set.UnionWith(s2.set);
            return(newSet);
        }
Beispiel #3
0
        public OclOrderedSet prepend <T>(OclClassifier newElementType, T item) where T : OclAny
        {
            OclOrderedSet set = new OclOrderedSet(newElementType, list);

            set.list.Insert(0, item);
            return(set);
        }
Beispiel #4
0
        public OclBag excluding <T>(OclClassifier newElementType, T item) where T : OclAny
        {
            OclBag bg = new OclBag(newElementType, map);

            bg.map.Remove(item);
            return(bg);
        }
Beispiel #5
0
        public OclSequence prepend <T>(OclClassifier newElementType, T item) where T : OclAny
        {
            OclSequence newList = new OclSequence(newElementType, list);

            newList.list.Insert(0, item);
            return(newList);
        }
Beispiel #6
0
        public OclSet including <T>(OclClassifier newElementType, T item) where T : OclAny
        {
            OclSet newSet = new OclSet(newElementType, set);

            newSet.set.Add(item);
            return(newSet);
        }
Beispiel #7
0
        public OclSequence union(OclClassifier newElementType, OclSequence s)
        {
            OclSequence newList = new OclSequence(newElementType, list);

            newList.list.AddRange(s);
            return(newList);
        }
Beispiel #8
0
        public OclOrderedSet insertAt <T>(OclClassifier newElementType, OclInteger index, T obj) where T : OclAny
        {
            OclOrderedSet o      = new OclOrderedSet(newElementType, list);
            int           indexI = (int)index;

            o.list.Insert(indexI - 1, obj);
            return(o);
        }
Beispiel #9
0
        public OclSequence insertAt <T>(OclClassifier newElementType, OclInteger index, T item) where T : OclAny
        {
            OclSequence newList  = new OclSequence(newElementType, list);
            int         intIndex = (int)index;

            newList.list.Insert(intIndex - 1, item);
            return(newList);
        }
Beispiel #10
0
 public static OclClassifier BasicElementType(OclClassifier cls)
 {
     while (cls is OclCollectionType)
     {
         cls = ((OclCollectionType)cls).elementType;
     }
     return(cls);
 }
Beispiel #11
0
        protected OclOrderedSet ClosureToOrderedSet <T>(OclClassifier newElementType, Func <T, OclAny> body)
            where T : OclAny
        {
            OclOrderedSet resultSet = new OclOrderedSet(newElementType);

            ClosureTo(newElementType, this, resultSet.list, body);
            return(resultSet);
        }
Beispiel #12
0
 public OclOrderedSet(OclClassifier elementType, params OclCollectionLiteralPart[] items) :
     base(elementType)
 {
     this.list = new List <OclAny>();
     foreach (OclCollectionLiteralPart item in items)
     {
         list.AddRange(item);
     }
 }
Beispiel #13
0
 public OclBag union(OclClassifier newElementType, OclBag s2)
 {
     if (IsNull(s2))
     {
         throw new ArgumentNullException();
     }
     //Use Bag implemetation
     return(s2.union(newElementType, this));
 }
Beispiel #14
0
 public OclBag(OclClassifier type, params OclCollectionLiteralPart[] items) :
     base(type)
 {
     this.map = new Dictionary <OclAny, int>();
     foreach (OclCollectionLiteralPart item in items)
     {
         AddRange(item);
     }
 }
Beispiel #15
0
 /// <summary>
 /// Create set with the specified element type and fill it with elements or integer ranges
 /// </summary>
 /// <param name="elementType">Element type</param>
 /// <param name="items">Array of elements or integer ranges</param>
 public OclSet(OclClassifier elementType, params OclCollectionLiteralPart[] items) :
     base(elementType)
 {
     this.set = new HashSet <OclAny>();
     foreach (OclCollectionLiteralPart item in items)
     {
         set.UnionWith(item);
     }
 }
Beispiel #16
0
        public OclBag union(OclClassifier newElementType, OclSet set)
        {
            if (IsNull(set))
            {
                throw new ArgumentNullException();
            }
            OclBag bg = new OclBag(newElementType, map);

            bg.AddRange(set);
            return(bg);
        }
Beispiel #17
0
 public T oclAsType <T>(OclClassifier type) where T : OclAny
 {
     if (oclType().ConformsToInternal(type))
     {
         return((T)this);
     }
     else
     {
         throw new InvalidCastException();
     }
 }
Beispiel #18
0
        public static int Depth(OclClassifier cls)
        {
            int depth = 0;

            while (cls is OclCollectionType)
            {
                ++depth;
                cls = ((OclCollectionType)cls).elementType;
            }
            return(depth);
        }
Beispiel #19
0
 internal override bool ConformsToInternal(OclClassifier cls)
 {
     //Collection conforms to OclAny
     if (cls == AnyType.OclAny)
     {
         return(true);
     }
     else if (cls is OclCollectionType) //Collection conforms to collection of same kind or CollectionKind of conformant element type
     {
         OclCollectionType ct = (OclCollectionType)cls;
         return((ct.kind == OclCollectionKind.Collection || ct.kind == kind) && elementType.ConformsToInternal(ct.elementType));
     }
     else
     {
         return(false);
     }
 }
Beispiel #20
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();
                     }
                 }
             }
         }
     }
 }
Beispiel #21
0
 internal override bool ConformsToInternal(OclClassifier cls)
 {
     //Classes and interfaces conform to Any
     if (cls == OclAny.Type)
     {
         return(true);
     }
     else if (cls is OclObjectType)
     {
         //Classes and interfaces conform to ancestor classes and interfaces
         OclObjectType tt = (OclObjectType)cls;
         return(tt.type.IsAssignableFrom(type));
     }
     else
     {
         return(false);
     }
 }
Beispiel #22
0
 internal override bool ConformsToInternal(OclClassifier cls)
 {
     //Tuples conform to OclAny
     if (cls.GetType() == typeof(OclAny))
     {
         return(true);
     }
     else if (cls.GetType() == typeof(OclTupleType))
     {
         //Tuple conforms to another tuple if they have parts of same names and order and conforming types
         OclTupleType tt = (OclTupleType)cls;
         if (tt.parts.Count != parts.Count)
         {
             return(false);
         }
         else
         {
             //Each tuple part typ must conform to the corresponding part type
             foreach (var part in parts)
             {
                 OclClassifier partType;
                 if (!tt.parts.TryGetValue(part.Key, out partType))
                 {
                     return(false);
                 }
                 if (!part.Value.ConformsToInternal(partType))
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #23
0
 public static TuplePart Part(string name, OclClassifier type, OclAny value)
 {
     return(new TuplePart {
         name = name, type = type, value = value
     });
 }
Beispiel #24
0
 public OclBag(OclClassifier type, params OclAny[] elements) :
     this(type, (IEnumerable <OclAny>)elements)
 {
 }
Beispiel #25
0
 /// <summary>
 /// Construct a new bag containing elements from the specified collection
 /// </summary>
 /// <param name="type">Element type</param>
 /// <param name="elements">Collection of values</param>
 public OclBag(OclClassifier type, IEnumerable <OclAny> elements) :
     base(type)
 {
     map = new Dictionary <OclAny, int>();
     AddRange(elements);
 }
Beispiel #26
0
 public OclBag collectNested <T, K>(OclClassifier newElementType, Func <T, K> f)
     where T : OclAny
     where K : OclAny
 {
     return(new OclBag(newElementType, this.Select(x => f((T)x))));
 }
Beispiel #27
0
 public OclBag collectToBag <T>(OclClassifier newElementType, Func <T, OclAny> f)
     where T : OclAny
 {
     return(collectNested(newElementType, f).flattenToBag());
 }
Beispiel #28
0
 public override OclCollection collect <T>(OclClassifier newElementType, Func <T, OclAny> f)
 {
     return(collectToBag <T>(newElementType, f));
 }
Beispiel #29
0
 internal OclObject(OclClassifier type, object value)
 {
     this.type  = type;
     this.value = value;
 }
Beispiel #30
0
 public OclSet closureToSet <T>(OclClassifier newElementType, Func <T, OclAny> body) where T : OclAny
 {
     return(ClosureToSet <T>(newElementType, body));
 }