当前位置: 首页>>代码示例>>Java>>正文


Java TreeMap.pollFirstEntry方法代码示例

本文整理汇总了Java中java.util.TreeMap.pollFirstEntry方法的典型用法代码示例。如果您正苦于以下问题:Java TreeMap.pollFirstEntry方法的具体用法?Java TreeMap.pollFirstEntry怎么用?Java TreeMap.pollFirstEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.TreeMap的用法示例。


在下文中一共展示了TreeMap.pollFirstEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: trimToSize

import java.util.TreeMap; //导入方法依赖的package包/类
private void trimToSize() {
    final long maxSize = sizePolicy.size;
    final long currentSize = size();
    Log.d(TAG, String.format("max: %d, current %d", maxSize, currentSize));
    if (currentSize > maxSize) {
        Log.d(TAG, "Attempting clean up");
        final List<String> keys = cacheBook.getAllKeys();
        final TreeMap<Long, String> sortedKeyMap = new TreeMap<>();
        for (final String key : keys) {
            sortedKeyMap.put(readCacheEntry(key).lastModified, key);
        }
        while (size() > maxSize) {
            final Map.Entry<Long, String> firstEntry = sortedKeyMap.pollFirstEntry();
            final String keyToEvict = firstEntry.getValue();
            Log.d(TAG, "Evicting : " + keyToEvict);
            remove(keyToEvict);
        }
    }
}
 
开发者ID:arunkumar9t2,项目名称:PaperDiskCache,代码行数:20,代码来源:PaperDiskCache.java

示例2: testPollFirstEntry

import java.util.TreeMap; //导入方法依赖的package包/类
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    TreeMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:TreeMapTest.java

示例3: mergeSorted

import java.util.TreeMap; //导入方法依赖的package包/类
/**
 * Merges already-sorted sections, reading one value from each dex into memory
 * at a time.
 */
public final void mergeSorted() {
    TableOfContents.Section[] sections = new TableOfContents.Section[dexes.length];
    Dex.Section[] dexSections = new Dex.Section[dexes.length];
    int[] offsets = new int[dexes.length];
    int[] indexes = new int[dexes.length];

    // values contains one value from each dex, sorted for fast retrieval of
    // the smallest value. The list associated with a value has the indexes
    // of the dexes that had that value.
    TreeMap<T, List<Integer>> values = new TreeMap<T, List<Integer>>();

    for (int i = 0; i < dexes.length; i++) {
        sections[i] = getSection(dexes[i].getTableOfContents());
        dexSections[i] = sections[i].exists() ? dexes[i].open(sections[i].off) : null;
        // Fill in values with the first value of each dex.
        offsets[i] = readIntoMap(
                dexSections[i], sections[i], indexMaps[i], indexes[i], values, i);
    }
    getSection(contentsOut).off = out.getPosition();

    int outCount = 0;
    while (!values.isEmpty()) {
        Map.Entry<T, List<Integer>> first = values.pollFirstEntry();
        for (Integer dex : first.getValue()) {
            updateIndex(offsets[dex], indexMaps[dex], indexes[dex]++, outCount);
            // Fetch the next value of the dexes we just polled out
            offsets[dex] = readIntoMap(dexSections[dex], sections[dex],
                    indexMaps[dex], indexes[dex], values, dex);
        }
        write(first.getKey());
        outCount++;
    }

    getSection(contentsOut).size = outCount;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:DexMerger.java


注:本文中的java.util.TreeMap.pollFirstEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。