/// <summary> /// Compares two product partition nodes. /// </summary> /// <param name="leftNode">The left node.</param> /// <param name="rightNode">The right node.</param> private static void CompareTree(ProductPartitionNode leftNode, ProductPartitionNode rightNode) { ProductDimensionEqualityComparer comparer = new ProductDimensionEqualityComparer(); Assert.True(comparer.Equals(leftNode.Dimension, rightNode.Dimension)); Assert.AreEqual(leftNode.Children.Count(), rightNode.Children.Count()); for (int i = 0; i < leftNode.Children.Count(); i++) { ProductPartitionNode leftChildNode = leftNode.Children.ElementAt(i); bool foundMatch = false; for (int j = 0; j < rightNode.Children.Count(); j++) { ProductPartitionNode rightChildNode = rightNode.Children.ElementAt(j); if (comparer.Equals(leftChildNode.Dimension, rightChildNode.Dimension)) { CompareTree(leftChildNode, rightChildNode); foundMatch = true; break; } } Assert.True(foundMatch, "Matching node not found."); } }
/// <summary> /// Gets the operations for node. /// </summary> /// <param name="partitionNode">The partition node.</param> /// <param name="mutateOperations">The list of all mutate operations.</param> /// <returns>The list of operations that apply to partitionNode.</returns> internal List <AdGroupCriterionOperation> GetOperationsForNode( ProductPartitionNode partitionNode, AdGroupCriterionOperation[] mutateOperations) { ProductDimensionEqualityComparer comparer = new ProductDimensionEqualityComparer(); List <AdGroupCriterionOperation> retval = new List <AdGroupCriterionOperation>(); foreach (AdGroupCriterionOperation operation in mutateOperations) { switch (operation.@operator) { case Operator.SET: case Operator.REMOVE: if (operation.operand.criterion.id == partitionNode.ProductPartitionId) { retval.Add(operation); } break; case Operator.ADD: if (comparer.Equals((operation.operand.criterion as ProductPartition).caseValue, partitionNode.Dimension)) { retval.Add(operation); } break; } } return(retval); }
/// <summary> /// Constructor that initializes the temp ID generator based on the ID of /// the root node. /// </summary> /// <param name="adGroupId">the ID of the ad group.</param> /// <param name="root">The root node of the tree.</param> private ProductPartitionTree(long adGroupId, ProductPartitionNode root) { PreconditionUtilities.CheckNotNull(root, ShoppingMessages.RootNodeCannotBeNull); this.adGroupId = adGroupId; this.root = root; this.dimensionComparator = new ProductDimensionEqualityComparer(); // If this is an existing node in an ad group, then the tree should be // cloned so that we can keep track of the original state of the tree. if (this.Root.ProductPartitionId > 0) { originalRoot = this.Root.Clone(); } }
/// <summary> /// Gets the operations for node. /// </summary> /// <param name="partitionNode">The partition node.</param> /// <param name="mutateOperations">The list of all mutate operations.</param> /// <returns>The list of operations that apply to partitionNode.</returns> internal List<AdGroupCriterionOperation> GetOperationsForNode( ProductPartitionNode partitionNode, AdGroupCriterionOperation[] mutateOperations) { ProductDimensionEqualityComparer comparer = new ProductDimensionEqualityComparer(); List<AdGroupCriterionOperation> retval = new List<AdGroupCriterionOperation>(); foreach (AdGroupCriterionOperation operation in mutateOperations) { switch (operation.@operator) { case Operator.SET: case Operator.REMOVE: if (operation.operand.criterion.id == partitionNode.ProductPartitionId) { retval.Add(operation); } break; case Operator.ADD: if (comparer.Equals((operation.operand.criterion as ProductPartition).caseValue, partitionNode.Dimension)) { retval.Add(operation); } break; } } return retval; }