public synchronized void replace(@Nullable final Predicate<K> keysToReplace, @NonNull final Map<K, GeoItem> items, final boolean show) {
        final List<K> keysToRemove = new ArrayList<>();
        //collect what needs to be removed
        for (K key : itemMap.keySet()) {
            if ((keysToReplace == null || keysToReplace.test(key)) && !items.containsKey(key)) {
                keysToRemove.add(key);
            }
        }
        //remove what needs to be removed
        for (K key : keysToRemove) {
            remove(key);
        }
        //put all the rest
        for (Map.Entry<K, GeoItem> entry : items.entrySet()) {
            put(entry.getKey(), entry.getValue(), show);
        }
    }
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