本文整理汇总了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);
}
}
}
示例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);
}
示例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;
}