}
public static void runExample(AdWordsServices adWordsServices, AdWordsSession session,
Long adGroupId) throws Exception {
// Get the ad group criterion service.
AdGroupCriterionServiceInterface adGroupCriterionService =
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
ProductPartitionHelper helper = new ProductPartitionHelper(adGroupId);
// The most trivial partition tree has only a unit nodes as the root:
// helper.createUnit(null, null, 100000L);
ProductPartition root = helper.createSubdivision(null, null);
ProductCanonicalCondition newProductCondition = new ProductCanonicalCondition();
newProductCondition.setCondition(ProductCanonicalConditionCondition.NEW);
helper.createUnit(root, newProductCondition, 200000L);
ProductCanonicalCondition usedProductCondition = new ProductCanonicalCondition();
usedProductCondition.setCondition(ProductCanonicalConditionCondition.USED);
helper.createUnit(root, usedProductCondition, 100000L);
ProductPartition otherCondition =
helper.createSubdivision(root, new ProductCanonicalCondition());
ProductBrand coolProductBrand = new ProductBrand();
coolProductBrand.setValue("CoolBrand");
helper.createUnit(otherCondition, coolProductBrand, 900000L);
ProductBrand cheapProductBrand = new ProductBrand();
cheapProductBrand.setValue("CheapBrand");
helper.createUnit(otherCondition, cheapProductBrand, 10000L);
ProductPartition otherBrand = helper.createSubdivision(otherCondition, new ProductBrand());
// The value for the bidding category is a fixed ID for the 'Luggage & Bags'
// category. You can retrieve IDs for categories from the ConstantDataService.
// See the 'GetProductCategoryTaxonomy' example for more details.
ProductBiddingCategory biddingCategory = new ProductBiddingCategory();
biddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
biddingCategory.setValue(-5914235892932915235L);
helper.createUnit(otherBrand, biddingCategory, 750000L);
ProductBiddingCategory otherBiddingCategory = new ProductBiddingCategory();
otherBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
helper.createUnit(otherBrand, otherBiddingCategory, 110000L);
// Make the mutate request.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(helper.getOperations());
// For each criterion, make a list containing each of its children.
// We always create the parent before the child, so we can rely on that here.
Map<Long, List<ProductPartition>> children = Maps.newHashMap();
ProductPartition rootNode = null;