/// <summary> /// Add element to multiplicity. /// </summary> /// <param name="value"></param> public void Insert(ElementType value) { var newElement = new MultiplicityElement() { Value = value, Next = null, }; if (IsEmpty()) { head = newElement; return; } MultiplicityElement tempElement = head; while (tempElement.Next != null) { if (tempElement.Next == null) { return; } if (tempElement.Value.Equals(value)) { return; } tempElement = tempElement.Next; } tempElement.Next = newElement; }
/// <summary> /// Getting result of intersection of two multiplicity. /// </summary> /// <param name="First"></param> /// <param name="Second"></param> public void Intersection(Multiplicity <ElementType> First, Multiplicity <ElementType> Second) { this.head = null; if ((First.IsEmpty()) || (Second.IsEmpty())) { this.head = null; return; } MultiplicityElement tempFirst = First.head; MultiplicityElement tempSecond = Second.head; while (tempFirst != null) { while (tempSecond != null) { if (tempFirst.Value.Equals(tempSecond.Value)) { this.Insert(tempFirst.Value); } tempSecond = tempSecond.Next; } tempFirst = tempFirst.Next; tempSecond = Second.head; } }
/// <summary> /// Delete one of the multiplicity's element. /// </summary> /// <param name="value"></param> public void RemovingOfElement(ElementType value) { MultiplicityElement tempElement = head; MultiplicityElement elementBeforeTemp = head; while (tempElement != null) { if (head.Value.Equals(value)) { head = head.Next; tempElement = null; return; } if (!tempElement.Value.Equals(value)) { elementBeforeTemp = tempElement; tempElement = tempElement.Next; } else { elementBeforeTemp.Next = tempElement.Next; tempElement = null; return; } } }
private int ChooseMultiplicity(MultiplicityElement multiplicityElement) { int lower = multiplicityElement.Lower.HasValue ? (int)multiplicityElement.Lower.Value : 0; int upper = multiplicityElement.Upper != NUml.Uml2.UnlimitedNatural.Infinity ? (int)multiplicityElement.Upper.Value : InfinityBound; if (multiplicityElement is PSMAssociation) { PSMAssociation association = (PSMAssociation)multiplicityElement; int occurrences = GetElementOccurrences(association); if (occurrences > 10 && association.Lower > 0) { Log.AddError(string.Format("Association {0} is recursive and causes infinite nesting.", association)); throw new XmlSchemaException(string.Format("Association {0} is recursive and causes infinite nesting.", association)); } if (MinimalTree) { return(lower); } else { return(RandomGenerator.Next(lower, upper + 1, occurrences - 1)); } } else { if (MinimalTree) { return(lower); } else { return(RandomGenerator.Next(lower, upper + 1)); } } }
/// <summary> /// Print of the list. /// </summary> /// <returns></returns> public string Print() { string result = ""; if (IsEmpty()) { result = "No elemenets in the list."; return(result); } MultiplicityElement tempElement = head; while (tempElement != null) { result = result + tempElement.Value + " "; tempElement = tempElement.Next; } return(result); }
/// <summary> /// Getting result of union of two multiplicity. /// </summary> /// <param name="First"></param> /// <param name="Second"></param> public void Union(Multiplicity <ElementType> First, Multiplicity <ElementType> Second) { this.head = null; MultiplicityElement tempFirst = First.head; MultiplicityElement tempSecond = Second.head; while (tempFirst != null) { this.Insert(tempFirst.Value); tempFirst = tempFirst.Next; } while (tempSecond != null) { this.Insert(tempSecond.Value); tempSecond = tempSecond.Next; } }
/// <summary> /// Check element's of interesting existence. /// </summary> /// <param name="value"></param> /// <returns></returns> public bool ExistenceChecking(ElementType value) { if (IsEmpty()) { return(false); } MultiplicityElement tempElement = head; while (tempElement != null) { if (!tempElement.Value.Equals(value)) { tempElement = tempElement.Next; } else { return(true); } } return(false); }
/// <summary> /// Delete List. /// </summary> /// <param name="value">Value to be pushed.</param> public void Removing() { head = null; }