Source:
<code>private void updateWorkspaceSnapshots(String workspaceId, Workspace current, Workspace update) { final Map<String, Environment> updateEnvironments = update.getConfig() .getEnvironments() .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, env -> new EnvironmentImpl(env.getValue()))); final Map <String, Environment> currentDiff = Sets.difference(current.getConfig().getEnvironments().entrySet(), updateEnvironments.entrySet()) .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); final Map <String, Environment> updateDiff = Sets.difference(updateEnvironments.entrySet(), current.getConfig().getEnvironments().entrySet()) .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); for (Map.Entry<String, Environment> env : currentDiff.entrySet()) { Environment envValue = env.getValue(); if (Collections.frequency(currentDiff.values(), envValue) == 1 && Collections.frequency(updateDiff.values(), envValue) == 1 && !updateDiff.containsKey(env.getKey())) { try { <START> updateEnvironmentSnapshots(workspaceId, env.getKey(), updateDiff.entrySet() <END> .stream() .filter(e -> e.getValue().equals(envValue)) .findAny() .orElse(null) .getKey()); } catch (ConflictException | SnapshotException | NotFoundException err) { LOG.error("Failed to update snapshots of '%s' environment in '%s' workspace.", env.getKey(), workspaceId, err); safeRemoveEnvironmentSnapshots(workspaceId, env.getKey()); } } else { safeRemoveEnvironmentSnapshots(workspaceId, env.getKey()); } } }</code><technical_language>get this while checking "frequency" java entrySet() .stream() .filter(e -> e.getValue().equals(envValue)) .findAny() .orElse(null) // .getKey()</technical_language>

Target:
private void updateWorkspaceSnapshots(String workspaceId, Workspace current, Workspace update) { final Map<String, Environment> updateEnvironments = update.getConfig() .getEnvironments() .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, env -> new EnvironmentImpl(env.getValue()))); final Map <String, Environment> currentDiff = Sets.difference(current.getConfig().getEnvironments().entrySet(), updateEnvironments.entrySet()) .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); final Map <String, Environment> updateDiff = Sets.difference(updateEnvironments.entrySet(), current.getConfig().getEnvironments().entrySet()) .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); for (Map.Entry<String, Environment> env : currentDiff.entrySet()) { Environment envValue = env.getValue(); if (Collections.frequency(currentDiff.values(), envValue) == 1 && Collections.frequency(updateDiff.values(), envValue) == 1 && !updateDiff.containsKey(env.getKey())) { try { updateEnvironmentSnapshots(workspaceId, env.getKey(), updateDiff.entrySet() .stream() .filter(e -> e.getValue().equals(envValue)) .findAny() .orElse(null) .getKey()); } catch (ConflictException | SnapshotException | NotFoundException err) { LOG.error("Failed to update snapshots of '%s' environment in '%s' workspace.", env.getKey(), workspaceId, err); removeEnvironmentSnapshotsQuietly(workspaceId, env.getKey()); } } else { removeEnvironmentSnapshotsQuietly(workspaceId, env.getKey()); } } }