Source:
<code>public NodeAndInitialCredentials<Droplet> createNodeWithGroupEncodedIntoName(String group, final String name, Template template) { DigitalOceanTemplateOptions templateOptions = template.getOptions().as(DigitalOceanTemplateOptions.class); CreateDropletOptions.Builder options = CreateDropletOptions.builder(); options.addSshKeyId(defaultCredentials.get().getKey().getId()); if (!Strings.isNullOrEmpty(template.getOptions().getPublicKey())) { logger.debug(">> creating keypair for node..."); SshKey key = api.getKeyPairApi().create(name, template.getOptions().getPublicKey()); logger.debug(">> keypair created! %s", key); options.addSshKeyId(key.getId()); } if (!templateOptions.getSshKeyIds().isEmpty()) { options.addSshKeyIds(templateOptions.getSshKeyIds()); } if (templateOptions.getPrivateNetworking() != null) { options.privateNetworking(templateOptions.getPrivateNetworking()); } if (templateOptions.getBackupsEnabled() != null) { options.backupsEnabled(templateOptions.getBackupsEnabled()); } final String locationId = template.getLocation().getId(); <START> Region region = Iterables.find(api.getRegionApi().list(), new Predicate<Region>() { <END> @Override public boolean apply(Region input) { return input.getSlug().equals(locationId); } }); DropletCreation dropletCreation = api.getDropletApi().create(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template.getHardware().getProviderId()), region.getId(), options.build()); nodeRunningPredicate.apply(dropletCreation.getEventId()); Droplet droplet = api.getDropletApi().get(dropletCreation.getId()); return new NodeAndInitialCredentials<Droplet>(droplet, String.valueOf(droplet.getId()), null); }</code><technical_language>[minor] static import Iterables.find? OK if this blows if region found</technical_language>

Target:
public NodeAndInitialCredentials<Droplet> createNodeWithGroupEncodedIntoName(String group, final String name, Template template) { DigitalOceanTemplateOptions templateOptions = template.getOptions().as(DigitalOceanTemplateOptions.class); CreateDropletOptions.Builder options = CreateDropletOptions.builder(); Map<String, String> defaultKeys = keyGenerator.get(); logger.debug(">> creating default keypair for node..."); SshKey defaultKey = api.getKeyPairApi().create(name, defaultKeys.get("public")); logger.debug(">> keypair created! %s", defaultKey); options.addSshKeyId(defaultKey.getId()); if (!Strings.isNullOrEmpty(template.getOptions().getPublicKey())) { logger.debug(">> creating user keypair for node..."); SshKey key = api.getKeyPairApi().create(name, template.getOptions().getPublicKey()); logger.debug(">> keypair created! %s", key); options.addSshKeyId(key.getId()); } if (!templateOptions.getSshKeyIds().isEmpty()) { options.addSshKeyIds(templateOptions.getSshKeyIds()); } if (templateOptions.getPrivateNetworking() != null) { options.privateNetworking(templateOptions.getPrivateNetworking()); } if (templateOptions.getBackupsEnabled() != null) { options.backupsEnabled(templateOptions.getBackupsEnabled()); } final String locationId = template.getLocation().getId(); Region region = find(api.getRegionApi().list(), new Predicate<Region>() { @Override public boolean apply(Region input) { return input.getSlug().equals(locationId); } }); DropletCreation dropletCreation = api.getDropletApi().create(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template.getHardware().getProviderId()), region.getId(), options.build()); nodeRunningPredicate.apply(dropletCreation.getEventId()); Droplet droplet = api.getDropletApi().get(dropletCreation.getId()); LoginCredentials defaultCredentials = LoginCredentials.builder().user("root") .privateKey(defaultKeys.get("private")).build(); return new NodeAndInitialCredentials<Droplet>(droplet, String.valueOf(droplet.getId()), defaultCredentials); }