本文整理匯總了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;
}