/// <summary>Set <paramref name="coordinator"/> as the ONLY coordinating conjunction of the CoordinatedPhraseElement we're going to build.</summary> /// <remarks>If we already have a coordinating conjunction and try to add another one, throw an exception.</remarks> private void SetCoordinator(ConjunctionBuilder coordinator) { if (Coordinators.Count() == 0) { AddChildWithRole(coordinator, ChildRole.Coordinator); } else { throw new InvalidOperationException("Can't add multiple coordinators to a coordinated phrase"); } }
/// <summary>This constructor is called when a CoordinablePhraseBuilder transforms itself into a CoordinatedPhraseBuilder during Coordinate.</summary> /// <remarks>This implementation creates a CoordinatedPhraseBuilder that contains only coordinated elements and optionally a coordinating word. Subclasses may need /// to override with implementations that bring in additional syntax elements.<para>The argument <paramref name="childOrderings"/> may contain ChildOrderings /// referring to elements that are not coordinated elements or a coordinator. We remove those orderings here.</para></remarks> internal CoordinatedPhraseBuilder(phraseCategory category, IEnumerable <IElementTreeNode> coordinated, ConjunctionBuilder coordinator, HashSet <ChildOrdering> childOrderings) : base() { Phrase = new CoordinatedPhraseElement(category); SetCoordinatedElements(coordinated); SetCoordinator(coordinator); ChildOrderings = childOrderings; HashSet <IElementTreeNode> childrenInOrderingsThatHaveNotBeenMovedYet = new HashSet <IElementTreeNode>(); foreach (ChildOrdering ordering in ChildOrderings) { if (!Children.Contains(ordering.Before)) { childrenInOrderingsThatHaveNotBeenMovedYet.Add(ordering.Before); } if (!Children.Contains(ordering.After)) { childrenInOrderingsThatHaveNotBeenMovedYet.Add(ordering.After); } } foreach (IElementTreeNode missingChild in childrenInOrderingsThatHaveNotBeenMovedYet) { RemoveChildOrderingsThatReferTo(missingChild); } }