private void replaceGroupInMap(final K key, @Nullable final GeoItem oldItem, @Nullable final GeoItem newItem) {

        mapWriter.multiChange((putAction, removeAction) -> {
            final Map<Integer, GeoPrimitive> toRemove = LOCAL_MAP.get();
            final Map<Integer, GeoPrimitive> toPut = LOCAL_MAP_2.get();

            //get elements from old and new group
            fillMapFromGroup(oldItem, Objects.requireNonNull(toRemove));
            fillMapFromGroup(newItem, Objects.requireNonNull(toPut));
            //everything which is both in old and new group must not be removed
            for (Integer i : toPut.keySet()) {
                toRemove.remove(i);
            }
            for (Map.Entry<Integer, GeoPrimitive> entry : toRemove.entrySet()) {
                removeAction.call(new MapWriterGeoGroupKey<>(key, entry.getKey()));
            }
            for (Map.Entry<Integer, GeoPrimitive> entry : toPut.entrySet()) {
                putAction.call(new MapWriterGeoGroupKey<>(key, entry.getKey()), entry.getValue());
            }
            toPut.clear();
            toRemove.clear();
        });
    }
Replaces a set of items (identified by keysToReplace) with the given items. Prevents unnecessary remove+put for same key
main/src/main/java/cgeo/geocaching/unifiedmap/geoitemlayer/GeoItemLayer.java