Source:
<code>public void apply(ServiceContext context, Optional<BaragonService> maybeOldService, boolean revertOnFailure) throws InvalidConfigException, LbAdapterExecuteException, IOException, MissingTemplateException { final BaragonService service = context.getService(); <START> final BaragonService oldService; <END> if (maybeOldService.isPresent()) { oldService = maybeOldService.get(); } else { oldService = service; } LOG.info(String.format("Going to apply %s: %s", service.getServiceId(), Joiner.on(", ").join(context.getUpstreams()))); final boolean oldServiceExists = configsExist(oldService); final boolean previousConfigsExist = configsExist(service); Collection<BaragonConfigFile> newConfigs = configGenerator.generateConfigsForProject(context); if (newConfigs.equals(readConfigs(oldService))) { LOG.info(" Configs are unchanged, skipping apply"); return; } if (revertOnFailure) { backupConfigs(service); if (oldServiceExists) { backupConfigs(oldService); } } try { if (context.isPresent()) { writeConfigs(newConfigs); if (oldServiceExists && !oldService.getServiceId().equals(service.getServiceId())) { remove(oldService, false); } } else { remove(service, false); } adapter.checkConfigs(); } catch (Exception e) { LOG.error("Caught exception while writing configs for " + service.getServiceId() + ", reverting to backups!", e); if (revertOnFailure) { if (oldServiceExists) { restoreConfigs(oldService); } if (previousConfigsExist) { restoreConfigs(service); } else { remove(service, false); } } throw Throwables.propagate(e); } adapter.reloadConfigs(); removeBackupConfigs(oldService); }</code><technical_language>simpler do maybeOldService.or(service)</technical_language>

Target:
public void apply(ServiceContext context, Optional<BaragonService> maybeOldService, boolean revertOnFailure) throws InvalidConfigException, LbAdapterExecuteException, IOException, MissingTemplateException { final BaragonService service = context.getService(); final BaragonService oldService = maybeOldService.or(service); LOG.info(String.format("Going to apply %s: %s", service.getServiceId(), Joiner.on(", ").join(context.getUpstreams()))); final boolean oldServiceExists = configsExist(oldService); final boolean previousConfigsExist = configsExist(service); Collection<BaragonConfigFile> newConfigs = configGenerator.generateConfigsForProject(context); if (newConfigs.equals(readConfigs(oldService))) { LOG.info(" Configs are unchanged, skipping apply"); return; } if (revertOnFailure) { backupConfigs(service); if (oldServiceExists) { backupConfigs(oldService); } } try { if (context.isPresent()) { writeConfigs(newConfigs); if (oldServiceExists && !oldService.getServiceId().equals(service.getServiceId())) { remove(oldService, false); } } else { remove(service, false); } adapter.checkConfigs(); } catch (Exception e) { LOG.error("Caught exception while writing configs for " + service.getServiceId() + ", reverting to backups!", e); if (revertOnFailure) { if (oldServiceExists && !oldService.equals(service)) { restoreConfigs(oldService); } if (previousConfigsExist) { restoreConfigs(service); } else { remove(service, false); } } throw Throwables.propagate(e); } adapter.reloadConfigs(); removeBackupConfigs(oldService); }