// Separate the ad units by size.
if (page.getResults() != null) {
for (AdUnit adUnit : page.getResults()) {
if (adUnit.getParentId() != null && adUnit.getAdUnitSizes() != null) {
for (AdUnitSize adUnitSize : adUnit.getAdUnitSizes()) {
Size size = adUnitSize.getSize();
if (size.getWidth() == 300 && size.getHeight() == 250) {
Set<String> adUnitIds =
new HashSet<String>(Arrays.asList(
mediumSquareAdUnitPlacement.getTargetedAdUnitIds()));
adUnitIds.add(adUnit.getId());
mediumSquareAdUnitPlacement.setTargetedAdUnitIds(
adUnitIds.toArray(new String[] {}));
} else if (size.getWidth() == 120 && size.getHeight() == 600) {
Set<String> adUnitIds =
new HashSet<String>(Arrays.asList(
skyscraperAdUnitPlacement.getTargetedAdUnitIds()));
adUnitIds.add(adUnit.getId());
skyscraperAdUnitPlacement.setTargetedAdUnitIds(adUnitIds.toArray(new String[] {}));
} else if (size.getWidth() == 468 && size.getHeight() == 60) {
Set<String> adUnitIds =
new HashSet<String>(
Arrays.asList(bannerAdUnitPlacement.getTargetedAdUnitIds()));
adUnitIds.add(adUnit.getId());
bannerAdUnitPlacement.setTargetedAdUnitIds(adUnitIds.toArray(new String[] {}));