<NME> GeoitemLayers.java
<BEF> package cgeo.geocaching.maps.mapsforge.v6.caches;

import org.mapsforge.map.layer.Layer;

import android.support.annotation.NonNull;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.Iterator;

public class GeoitemLayers implements Collection<GeoitemLayer> {

    private final HashMap<String, GeoitemLayer> geoitems = new HashMap<>();

    public Collection<String> getGeocodes() {
        return new ArrayList<>(geoitems.keySet());
    }

    public Collection<Layer> getAsLayers() {
        return new ArrayList<Layer>(this.geoitems.values());
    }

    public GeoitemLayer getItem(final String itemCode) {
        return geoitems.get(itemCode);
    }

    public Collection<Layer> getMatchingLayers(final Collection<String> newCodes) {
        final ArrayList<Layer> result = new ArrayList<>();
        for (final String code : newCodes) {
            if (geoitems.containsKey(code)) {
        return cacheCodes.size();
    }

        return result;
    }

    @Override
    public boolean add(final GeoitemLayer geoitem) {
        return geoitems.put(geoitem.getItemCode(), geoitem) != null;
    }

    @Override
    public boolean addAll(@NonNull final Collection<? extends GeoitemLayer> geoitemsIn) {
        boolean result = true;
        for (final GeoitemLayer geoitem : geoitemsIn) {
            if (!this.add(geoitem)) {
                result = false;
            }
        }
    }
    }

    @Override
    public void clear() {
        this.geoitems.clear();
    }

    @Override
    public boolean contains(final Object object) {
        return this.geoitems.containsValue(object);
    }

    @Override
    public boolean containsAll(@NonNull final Collection<?> items) {
        return this.geoitems.values().containsAll(items);
    }

    @Override
    public boolean isEmpty() {
        return this.geoitems.isEmpty();
    }

    @Override
    @NonNull
    public Iterator<GeoitemLayer> iterator() {
        return this.geoitems.values().iterator();
    }

    @Override
    public boolean remove(final Object object) {
        if (object instanceof GeoitemLayer) {
            final GeoitemLayer item = (GeoitemLayer) object;
            return this.geoitems.remove(item.getItem().getItemCode()) != null;
    }

    @Override
    public boolean removeAll(@NonNull final Collection<?> items) {
        boolean result = true;
        for (final Object item : items) {
            if (!this.remove(item)) {
                result = false;
            }
        }
    }

    @Override
    public boolean retainAll(@NonNull final Collection<?> items) {

        return this.geoitems.values().retainAll(items);
    }

    @Override
    public int size() {

        return this.geoitems.size();
    }

    @Override
    @NonNull
    public Object[] toArray() {

        return this.geoitems.values().toArray();
    }
    @SuppressWarnings("hiding")
    @Override
    @NonNull
    public <GeoitemLayer> GeoitemLayer[] toArray(@NonNull final GeoitemLayer[] array) {

        return this.geoitems.values().toArray(array);
    }

<MSG> Merge branch 'release'

<DFF> @@ -1,7 +1,5 @@
 package cgeo.geocaching.maps.mapsforge.v6.caches;
 
-import org.mapsforge.map.layer.Layer;
-
 import android.support.annotation.NonNull;
 
 import java.util.ArrayList;
@@ -9,23 +7,25 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 
+import org.mapsforge.map.layer.Layer;
+
 public class GeoitemLayers implements Collection<GeoitemLayer> {
 
     private final HashMap<String, GeoitemLayer> geoitems = new HashMap<>();
 
-    public Collection<String> getGeocodes() {
+    public synchronized Collection<String> getGeocodes() {
         return new ArrayList<>(geoitems.keySet());
     }
 
-    public Collection<Layer> getAsLayers() {
+    public synchronized Collection<Layer> getAsLayers() {
         return new ArrayList<Layer>(this.geoitems.values());
     }
 
-    public GeoitemLayer getItem(final String itemCode) {
+    public synchronized GeoitemLayer getItem(final String itemCode) {
         return geoitems.get(itemCode);
     }
 
-    public Collection<Layer> getMatchingLayers(final Collection<String> newCodes) {
+    public synchronized Collection<Layer> getMatchingLayers(final Collection<String> newCodes) {
         final ArrayList<Layer> result = new ArrayList<>();
         for (final String code : newCodes) {
             if (geoitems.containsKey(code)) {
@@ -35,16 +35,20 @@ public class GeoitemLayers implements Collection<GeoitemLayer> {
         return result;
     }
 
-    @Override
-    public boolean add(final GeoitemLayer geoitem) {
+    private boolean addInternal(final GeoitemLayer geoitem) {
         return geoitems.put(geoitem.getItemCode(), geoitem) != null;
     }
 
     @Override
-    public boolean addAll(@NonNull final Collection<? extends GeoitemLayer> geoitemsIn) {
+    public synchronized boolean add(final GeoitemLayer geoitem) {
+        return addInternal(geoitem);
+    }
+
+    @Override
+    public synchronized boolean addAll(@NonNull final Collection<? extends GeoitemLayer> geoitemsIn) {
         boolean result = true;
         for (final GeoitemLayer geoitem : geoitemsIn) {
-            if (!this.add(geoitem)) {
+            if (!this.addInternal(geoitem)) {
                 result = false;
             }
         }
@@ -52,33 +56,32 @@ public class GeoitemLayers implements Collection<GeoitemLayer> {
     }
 
     @Override
-    public void clear() {
+    public synchronized void clear() {
         this.geoitems.clear();
     }
 
     @Override
-    public boolean contains(final Object object) {
+    public synchronized boolean contains(final Object object) {
         return this.geoitems.containsValue(object);
     }
 
     @Override
-    public boolean containsAll(@NonNull final Collection<?> items) {
+    public synchronized boolean containsAll(@NonNull final Collection<?> items) {
         return this.geoitems.values().containsAll(items);
     }
 
     @Override
-    public boolean isEmpty() {
+    public synchronized boolean isEmpty() {
         return this.geoitems.isEmpty();
     }
 
     @Override
     @NonNull
-    public Iterator<GeoitemLayer> iterator() {
-        return this.geoitems.values().iterator();
+    public synchronized Iterator<GeoitemLayer> iterator() {
+        return new ArrayList<>(this.geoitems.values()).iterator();
     }
 
-    @Override
-    public boolean remove(final Object object) {
+    private boolean removeInternal(final Object object) {
         if (object instanceof GeoitemLayer) {
             final GeoitemLayer item = (GeoitemLayer) object;
             return this.geoitems.remove(item.getItem().getItemCode()) != null;
@@ -89,10 +92,15 @@ public class GeoitemLayers implements Collection<GeoitemLayer> {
     }
 
     @Override
-    public boolean removeAll(@NonNull final Collection<?> items) {
+    public synchronized boolean remove(final Object object) {
+        return removeInternal(object);
+    }
+
+    @Override
+    public synchronized boolean removeAll(@NonNull final Collection<?> items) {
         boolean result = true;
         for (final Object item : items) {
-            if (!this.remove(item)) {
+            if (!this.removeInternal(item)) {
                 result = false;
             }
         }
@@ -100,20 +108,20 @@ public class GeoitemLayers implements Collection<GeoitemLayer> {
     }
 
     @Override
-    public boolean retainAll(@NonNull final Collection<?> items) {
+    public synchronized boolean retainAll(@NonNull final Collection<?> items) {
 
         return this.geoitems.values().retainAll(items);
     }
 
     @Override
-    public int size() {
+    public synchronized int size() {
 
         return this.geoitems.size();
     }
 
     @Override
     @NonNull
-    public Object[] toArray() {
+    public synchronized Object[] toArray() {
 
         return this.geoitems.values().toArray();
     }
@@ -121,7 +129,7 @@ public class GeoitemLayers implements Collection<GeoitemLayer> {
     @SuppressWarnings("hiding")
     @Override
     @NonNull
-    public <GeoitemLayer> GeoitemLayer[] toArray(@NonNull final GeoitemLayer[] array) {
+    public synchronized <GeoitemLayer> GeoitemLayer[] toArray(@NonNull final GeoitemLayer[] array) {
 
         return this.geoitems.values().toArray(array);
     }

Merge branch 'release'