public OclSequence append <T>(OclClassifier newElementType, T item) where T : OclAny { OclSequence newList = new OclSequence(newElementType, list); newList.list.Add(item); return(newList); }
public OclSet union(OclClassifier newElementType, OclSet s2) { OclSet newSet = new OclSet(newElementType, set); newSet.set.UnionWith(s2.set); return(newSet); }
public OclOrderedSet prepend <T>(OclClassifier newElementType, T item) where T : OclAny { OclOrderedSet set = new OclOrderedSet(newElementType, list); set.list.Insert(0, item); return(set); }
public OclBag excluding <T>(OclClassifier newElementType, T item) where T : OclAny { OclBag bg = new OclBag(newElementType, map); bg.map.Remove(item); return(bg); }
public OclSequence prepend <T>(OclClassifier newElementType, T item) where T : OclAny { OclSequence newList = new OclSequence(newElementType, list); newList.list.Insert(0, item); return(newList); }
public OclSet including <T>(OclClassifier newElementType, T item) where T : OclAny { OclSet newSet = new OclSet(newElementType, set); newSet.set.Add(item); return(newSet); }
public OclSequence union(OclClassifier newElementType, OclSequence s) { OclSequence newList = new OclSequence(newElementType, list); newList.list.AddRange(s); return(newList); }
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); }
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); }
public static OclClassifier BasicElementType(OclClassifier cls) { while (cls is OclCollectionType) { cls = ((OclCollectionType)cls).elementType; } return(cls); }
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); }
public OclOrderedSet(OclClassifier elementType, params OclCollectionLiteralPart[] items) : base(elementType) { this.list = new List <OclAny>(); foreach (OclCollectionLiteralPart item in items) { list.AddRange(item); } }
public OclBag union(OclClassifier newElementType, OclBag s2) { if (IsNull(s2)) { throw new ArgumentNullException(); } //Use Bag implemetation return(s2.union(newElementType, this)); }
public OclBag(OclClassifier type, params OclCollectionLiteralPart[] items) : base(type) { this.map = new Dictionary <OclAny, int>(); foreach (OclCollectionLiteralPart item in items) { AddRange(item); } }
/// <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); } }
public OclBag union(OclClassifier newElementType, OclSet set) { if (IsNull(set)) { throw new ArgumentNullException(); } OclBag bg = new OclBag(newElementType, map); bg.AddRange(set); return(bg); }
public T oclAsType <T>(OclClassifier type) where T : OclAny { if (oclType().ConformsToInternal(type)) { return((T)this); } else { throw new InvalidCastException(); } }
public static int Depth(OclClassifier cls) { int depth = 0; while (cls is OclCollectionType) { ++depth; cls = ((OclCollectionType)cls).elementType; } return(depth); }
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); } }
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(); } } } } } }
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); } }
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); } }
public static TuplePart Part(string name, OclClassifier type, OclAny value) { return(new TuplePart { name = name, type = type, value = value }); }
public OclBag(OclClassifier type, params OclAny[] elements) : this(type, (IEnumerable <OclAny>)elements) { }
/// <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); }
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)))); }
public OclBag collectToBag <T>(OclClassifier newElementType, Func <T, OclAny> f) where T : OclAny { return(collectNested(newElementType, f).flattenToBag()); }
public override OclCollection collect <T>(OclClassifier newElementType, Func <T, OclAny> f) { return(collectToBag <T>(newElementType, f)); }
internal OclObject(OclClassifier type, object value) { this.type = type; this.value = value; }
public OclSet closureToSet <T>(OclClassifier newElementType, Func <T, OclAny> body) where T : OclAny { return(ClosureToSet <T>(newElementType, body)); }