Tabnine Logo
LRUCache
Code IndexAdd Tabnine to your IDE (free)

How to use
LRUCache
in
org.mapsforge.core.util

Best Java code snippets using org.mapsforge.core.util.LRUCache (Showing top 17 results out of 315)

origin: mapsforge/mapsforge

/**
 * @param inputChannel the map file from which the index should be read and cached.
 * @param capacity     the maximum number of entries in the cache.
 * @throws IllegalArgumentException if the capacity is negative.
 */
IndexCache(FileChannel inputChannel, int capacity) {
  this.fileChannel = inputChannel;
  this.map = new LRUCache<IndexCacheEntryKey, byte[]>(capacity);
}
origin: mapsforge/mapsforge

/**
 * @param capacity the maximum capacity of this cache.
 * @throws IllegalArgumentException if the capacity is negative.
 */
public LRUCache(int capacity) {
  super(calculateInitialCapacity(capacity), LOAD_FACTOR, true);
  this.capacity = capacity;
}
origin: mapsforge/mapsforge

/**
 * Must be called when this RenderTheme gets destroyed to clean up and free resources.
 */
public void destroy() {
  this.poiMatchingCache.clear();
  this.wayMatchingCache.clear();
  for (Rule r : this.rulesList) {
    r.destroy();
  }
}
origin: mapsforge/mapsforge

/**
 * Matches a node with the given parameters against this RenderTheme.
 *
 * @param renderCallback the callback implementation which will be executed on each match.
 * @param renderContext
 * @param poi            the point of interest.
 */
public synchronized void matchNode(RenderCallback renderCallback, final RenderContext renderContext, PointOfInterest poi) {
  MatchingCacheKey matchingCacheKey = new MatchingCacheKey(poi.tags, renderContext.rendererJob.tile.zoomLevel, Closed.NO);
  List<RenderInstruction> matchingList = this.poiMatchingCache.get(matchingCacheKey);
  if (matchingList != null) {
    // cache hit
    for (int i = 0, n = matchingList.size(); i < n; ++i) {
      matchingList.get(i).renderNode(renderCallback, renderContext, poi);
    }
    return;
  }
  // cache miss
  matchingList = new ArrayList<RenderInstruction>();
  for (int i = 0, n = this.rulesList.size(); i < n; ++i) {
    this.rulesList.get(i).matchNode(renderCallback, renderContext, matchingList, poi);
  }
  this.poiMatchingCache.put(matchingCacheKey, matchingList);
}
origin: mapsforge/mapsforge

@Test
public void lruCacheTest() {
  LRUCache<String, String> lruCache = createLRUCache(2);
  lruCache.put(KEY1, VALUE1);
  Assert.assertEquals(VALUE1, lruCache.get(KEY1));
  Assert.assertFalse(lruCache.containsKey(KEY2));
  Assert.assertFalse(lruCache.containsKey(KEY3));
  lruCache.put(KEY2, VALUE2);
  Assert.assertEquals(VALUE1, lruCache.get(KEY1));
  Assert.assertEquals(VALUE2, lruCache.get(KEY2));
  Assert.assertFalse(lruCache.containsKey(KEY3));
  lruCache.put(KEY3, VALUE3);
  Assert.assertFalse(lruCache.containsKey(KEY1));
  Assert.assertEquals(VALUE2, lruCache.get(KEY2));
  Assert.assertEquals(VALUE3, lruCache.get(KEY3));
  lruCache.put(KEY1, VALUE1);
  Assert.assertEquals(VALUE1, lruCache.get(KEY1));
  Assert.assertFalse(lruCache.containsKey(KEY2));
  Assert.assertEquals(VALUE3, lruCache.get(KEY3));
}
origin: mapsforge/mapsforge

@Test
public void lruCacheWithCapacityZeroTest() {
  LRUCache<String, String> lruCache = createLRUCache(0);
  lruCache.put(KEY1, VALUE1);
  Assert.assertFalse(lruCache.containsKey(KEY1));
}
origin: mapsforge/mapsforge

  @Override
  protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
    return size() > this.capacity;
  }
}
origin: mapsforge/mapsforge

private synchronized void matchWay(RenderCallback renderCallback, final RenderContext renderContext, Closed closed, PolylineContainer way) {
  MatchingCacheKey matchingCacheKey = new MatchingCacheKey(way.getTags(), way.getUpperLeft().zoomLevel, closed);
  List<RenderInstruction> matchingList = this.wayMatchingCache.get(matchingCacheKey);
  if (matchingList != null) {
    // cache hit
    for (int i = 0, n = matchingList.size(); i < n; ++i) {
      matchingList.get(i).renderWay(renderCallback, renderContext, way);
    }
    return;
  }
  // cache miss
  matchingList = new ArrayList<RenderInstruction>();
  for (int i = 0, n = this.rulesList.size(); i < n; ++i) {
    this.rulesList.get(i).matchWay(renderCallback, way, way.getUpperLeft(), closed, matchingList, renderContext);
  }
  this.wayMatchingCache.put(matchingCacheKey, matchingList);
}
origin: org.mapsforge/mapsforge-core

  @Override
  protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
    return size() > this.capacity;
  }
}
origin: org.mapsforge/mapsforge-map

/**
 * Matches a node with the given parameters against this RenderTheme.
 *
 * @param renderCallback the callback implementation which will be executed on each match.
 * @param renderContext
 * @param poi            the point of interest.
 */
public synchronized void matchNode(RenderCallback renderCallback, final RenderContext renderContext, PointOfInterest poi) {
  MatchingCacheKey matchingCacheKey = new MatchingCacheKey(poi.tags, renderContext.rendererJob.tile.zoomLevel, Closed.NO);
  List<RenderInstruction> matchingList = this.poiMatchingCache.get(matchingCacheKey);
  if (matchingList != null) {
    // cache hit
    for (int i = 0, n = matchingList.size(); i < n; ++i) {
      matchingList.get(i).renderNode(renderCallback, renderContext, poi);
    }
    return;
  }
  // cache miss
  matchingList = new ArrayList<RenderInstruction>();
  for (int i = 0, n = this.rulesList.size(); i < n; ++i) {
    this.rulesList.get(i).matchNode(renderCallback, renderContext, matchingList, poi);
  }
  this.poiMatchingCache.put(matchingCacheKey, matchingList);
}
origin: mapsforge/mapsforge

RenderTheme(RenderThemeBuilder renderThemeBuilder) {
  this.baseStrokeWidth = renderThemeBuilder.baseStrokeWidth;
  this.baseTextSize = renderThemeBuilder.baseTextSize;
  this.hasBackgroundOutside = renderThemeBuilder.hasBackgroundOutside;
  this.mapBackground = renderThemeBuilder.mapBackground;
  this.mapBackgroundOutside = renderThemeBuilder.mapBackgroundOutside;
  this.rulesList = new ArrayList<>();
  this.poiMatchingCache = new LRUCache<>(MATCHING_CACHE_SIZE);
  this.wayMatchingCache = new LRUCache<>(MATCHING_CACHE_SIZE);
}
origin: org.mapsforge/mapsforge-core

/**
 * @param capacity the maximum capacity of this cache.
 * @throws IllegalArgumentException if the capacity is negative.
 */
public LRUCache(int capacity) {
  super(calculateInitialCapacity(capacity), LOAD_FACTOR, true);
  this.capacity = capacity;
}
origin: org.mapsforge/mapsforge-map

/**
 * Must be called when this RenderTheme gets destroyed to clean up and free resources.
 */
public void destroy() {
  this.poiMatchingCache.clear();
  this.wayMatchingCache.clear();
  for (Rule r : this.rulesList) {
    r.destroy();
  }
}
origin: org.mapsforge/mapsforge-map

private synchronized void matchWay(RenderCallback renderCallback, final RenderContext renderContext, Closed closed, PolylineContainer way) {
  MatchingCacheKey matchingCacheKey = new MatchingCacheKey(way.getTags(), way.getUpperLeft().zoomLevel, closed);
  List<RenderInstruction> matchingList = this.wayMatchingCache.get(matchingCacheKey);
  if (matchingList != null) {
    // cache hit
    for (int i = 0, n = matchingList.size(); i < n; ++i) {
      matchingList.get(i).renderWay(renderCallback, renderContext, way);
    }
    return;
  }
  // cache miss
  matchingList = new ArrayList<RenderInstruction>();
  for (int i = 0, n = this.rulesList.size(); i < n; ++i) {
    this.rulesList.get(i).matchWay(renderCallback, way, way.getUpperLeft(), closed, matchingList, renderContext);
  }
  this.wayMatchingCache.put(matchingCacheKey, matchingList);
}
origin: mapsforge/mapsforge

private static LRUCache<String, String> createLRUCache(int capacity) {
  LRUCache<String, String> lruCache = new LRUCache<>(capacity);
  Assert.assertEquals(capacity, lruCache.capacity);
  return lruCache;
}
origin: org.mapsforge/mapsforge-map-reader

/**
 * @param inputChannel the map file from which the index should be read and cached.
 * @param capacity     the maximum number of entries in the cache.
 * @throws IllegalArgumentException if the capacity is negative.
 */
IndexCache(FileChannel inputChannel, int capacity) {
  this.fileChannel = inputChannel;
  this.map = new LRUCache<IndexCacheEntryKey, byte[]>(capacity);
}
origin: org.mapsforge/mapsforge-map

RenderTheme(RenderThemeBuilder renderThemeBuilder) {
  this.baseStrokeWidth = renderThemeBuilder.baseStrokeWidth;
  this.baseTextSize = renderThemeBuilder.baseTextSize;
  this.hasBackgroundOutside = renderThemeBuilder.hasBackgroundOutside;
  this.mapBackground = renderThemeBuilder.mapBackground;
  this.mapBackgroundOutside = renderThemeBuilder.mapBackgroundOutside;
  this.rulesList = new ArrayList<>();
  this.poiMatchingCache = new LRUCache<>(MATCHING_CACHE_SIZE);
  this.wayMatchingCache = new LRUCache<>(MATCHING_CACHE_SIZE);
}
org.mapsforge.core.utilLRUCache

Javadoc

An LRUCache with a fixed size and an access-order policy. Old mappings are automatically removed from the cache when new mappings are added. This implementation uses an LinkedHashMap internally.

Most used methods

  • <init>
  • get
  • put
  • calculateInitialCapacity
  • clear
  • size
  • containsKey

Popular in Java

  • Finding current android device location
  • getSystemService (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • scheduleAtFixedRate (Timer)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JTextField (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now