List<Placement> placementsToCreate = Lists.newArrayList();
// Only create placements with one or more ad unit.
if (!mediumSquareAdUnitIds.isEmpty()) {
// Create medium square placement.
Placement mediumSquareAdUnitPlacement = new Placement();
mediumSquareAdUnitPlacement.setName("Medium Square AdUnit Placement #"
+ new Random().nextInt(Integer.MAX_VALUE));
mediumSquareAdUnitPlacement.setDescription(
"Contains ad units that can hold creatives of size 300x250");
mediumSquareAdUnitPlacement.setTargetedAdUnitIds(
mediumSquareAdUnitIds.toArray(new String[] {}));
placementsToCreate.add(mediumSquareAdUnitPlacement);
}
if (!skyscraperAdUnitIds.isEmpty()) {
// Create skyscraper placement.
Placement skyscraperAdUnitPlacement = new Placement();
skyscraperAdUnitPlacement.setName(
"Skyscraper AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
skyscraperAdUnitPlacement.setDescription(
"Contains ad units that can hold creatives of size 120x600");
skyscraperAdUnitPlacement.setTargetedAdUnitIds(skyscraperAdUnitIds.toArray(new String[] {}));
placementsToCreate.add(skyscraperAdUnitPlacement);
}
if (!bannerAdUnitIds.isEmpty()) {
// Create banner placement.
Placement bannerAdUnitPlacement = new Placement();
bannerAdUnitPlacement.setName(
"Banner AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
bannerAdUnitPlacement.setDescription(
"Contains ad units that can hold creatives of size 468x60");
bannerAdUnitPlacement.setTargetedAdUnitIds(bannerAdUnitIds.toArray(new String[] {}));
placementsToCreate.add(bannerAdUnitPlacement);
}
if (!placementsToCreate.isEmpty()) {
// Create the placements on the server.