Android Open Source - CartoCache Default Place Cache






From Project

Back to project page CartoCache.

License

The source code is released under:

Apache License

If you think the Android project CartoCache listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.codeandmagic.cartocache;
//from   w w w.j av a 2  s.  c  om
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by evelyne24.
 */
public class DefaultPlaceCache<P extends Place> implements PlacesCache<P> {

    private final Map<String, Collection<P>> cache;
    private final boolean multiLevelCache;

    public DefaultPlaceCache(boolean multiLevelCache) {
        this.multiLevelCache = multiLevelCache;
        this.cache = new HashMap<String, Collection<P>>();
    }

    @Override
    public void add(QTile qTile, Collection<P> places) {
        cache.put(qTile.quadKey, places);
    }

    @Override
    public boolean isMultiLevelCache() {
        return multiLevelCache;
    }

    @Override
    public Collection<P> get(QTile qTile) {
        final String quadKey = qTile.quadKey;

        if (multiLevelCache) {
            return cache.get(quadKey);
        } else {
            // Try to find an exact match
            Collection<P> match = cache.get(quadKey);
            if (match != null) {
                return match;
            }

            // Try to find a parent tile that has cached locations
            for (String maybeParentQuadKey : cache.keySet()) {
                if (quadKey.startsWith(maybeParentQuadKey)) {
                    return cache.get(maybeParentQuadKey);
                }
            }
            // not found
            return null;
        }
    }
}




Java Source Code List

com.codeandmagic.cartocache.CartoCacheConfig.java
com.codeandmagic.cartocache.CartoCache.java
com.codeandmagic.cartocache.DataFetcher.java
com.codeandmagic.cartocache.DefaultMarkerConfig.java
com.codeandmagic.cartocache.DefaultPlaceCache.java
com.codeandmagic.cartocache.L.java
com.codeandmagic.cartocache.LocationUtils.java
com.codeandmagic.cartocache.MarkerConfig.java
com.codeandmagic.cartocache.Place.java
com.codeandmagic.cartocache.PlacesCache.java
com.codeandmagic.cartocache.QTileDrawConfig.java
com.codeandmagic.cartocache.QTile.java
com.codeandmagic.cartocache.Utils.java
com.codeandmagic.cartocache.ZoomLevel.java
com.codeandmagic.cartocache.demo.DemoActivity.java
com.codeandmagic.cartocache.demo.DemoMapFragment.java
com.codeandmagic.cartocache.demo.GooglePlace.java
com.codeandmagic.cartocache.demo.GooglePlacesParser.java