本文整理汇总了Java中java.util.LinkedHashMap.Entry方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedHashMap.Entry方法的具体用法?Java LinkedHashMap.Entry怎么用?Java LinkedHashMap.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap.Entry方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllExtraWordsNameList
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static String[] getAllExtraWordsNameList(LinkedHashMap<String, String> data, boolean defaultOpinion, String defaultString) {
int length;
if (defaultOpinion) {
length = data.size() + 1;
} else {
length = data.size();
}
String[] result = new String[length];
int start = 0;
if (defaultOpinion && defaultString != null) {
result[0] = defaultString;
start++;
}
for (Object o : data.entrySet()) {
LinkedHashMap.Entry entry = (LinkedHashMap.Entry) o;
result[start] = entry.getKey().toString();
start++;
}
return result;
}
示例2: testGetMatchingEntries
import java.util.LinkedHashMap; //导入方法依赖的package包/类
@Test
public void testGetMatchingEntries() {
mCountingLruMap.put("key1", 110);
mCountingLruMap.put("key2", 120);
mCountingLruMap.put("key3", 130);
mCountingLruMap.put("key4", 140);
List<LinkedHashMap.Entry<String, Integer>> entries = mCountingLruMap.getMatchingEntries(
new Predicate<String>() {
@Override
public boolean apply(String key) {
return key.equals("key2") || key.equals("key3");
}
});
assertNotNull(entries);
assertEquals(2, entries.size());
assertEquals("key2", entries.get(0).getKey());
assertEquals(120, (int) entries.get(0).getValue());
assertEquals("key3", entries.get(1).getKey());
assertEquals(130, (int) entries.get(1).getValue());
// getting entries should not affect the order nor the size
assertEquals(4, mCountingLruMap.getCount());
assertEquals(500, mCountingLruMap.getSizeInBytes());
assertKeyOrder("key1", "key2", "key3", "key4");
assertValueOrder(110, 120, 130, 140);
}
示例3: getMatchingEntries
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/** Gets the all matching elements. */
public synchronized ArrayList<LinkedHashMap.Entry<K, V>> getMatchingEntries(
@Nullable Predicate<K> predicate) {
ArrayList<LinkedHashMap.Entry<K, V>> matchingEntries = new ArrayList<>(mMap.entrySet().size());
for (LinkedHashMap.Entry<K, V> entry : mMap.entrySet()) {
if (predicate == null || predicate.apply(entry.getKey())) {
matchingEntries.add(entry);
}
}
return matchingEntries;
}
示例4: removeAll
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/** Removes all the matching elements from the map. */
public synchronized ArrayList<V> removeAll(@Nullable Predicate<K> predicate) {
ArrayList<V> oldValues = new ArrayList<>();
Iterator<LinkedHashMap.Entry<K, V>> iterator = mMap.entrySet().iterator();
while (iterator.hasNext()) {
LinkedHashMap.Entry<K, V> entry = iterator.next();
if (predicate == null || predicate.apply(entry.getKey())) {
oldValues.add(entry.getValue());
mSizeInBytes -= getValueSizeInBytes(entry.getValue());
iterator.remove();
}
}
return oldValues;
}
示例5: removeEldestEntry
import java.util.LinkedHashMap; //导入方法依赖的package包/类
@Override
protected boolean removeEldestEntry(LinkedHashMap.Entry<Integer, Bitmap> eldest) {
if (size() > HARD_CACHE_CAPACITY) {
// Entries push-out of hard reference cache are transferred to
// soft reference cache
sSoftBitmapCache.put(eldest.getKey(), new SoftReference<Bitmap>(eldest.getValue()));
return true;
} else
return false;
}