/** * 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); }
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); }
@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)); }
/** * 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); }
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); }