下面列出了java.util.LinkedHashMap#Entry ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void handleNextJavaScript() {
handler.removeMessages(MESSAGE_HANDLE_NEXT_JAVASCRIPT);
Iterator<LinkedHashMap.Entry<String, CloudFlareClient>> iterator = clientHandlers.entrySet().iterator();
CloudFlareClient client = null;
if (iterator.hasNext()) {
iterator.next();
iterator.remove();
if (iterator.hasNext()) {
client = iterator.next().getValue();
}
}
if (client != null) {
handleJavaScript(client);
handler.sendEmptyMessageDelayed(MESSAGE_HANDLE_NEXT_JAVASCRIPT, WEB_VIEW_TIMEOUT);
}
}
public RestoreFragment(LinkedHashMap<File, String> filesMap) {
Bundle args = new Bundle();
ArrayList<String> files = new ArrayList<>(filesMap.size());
ArrayList<String> names = new ArrayList<>(filesMap.size());
for (LinkedHashMap.Entry<File, String> pair : filesMap.entrySet()) {
files.add(pair.getKey().getAbsolutePath());
names.add(pair.getValue());
}
args.putStringArrayList(EXTRA_FILES, files);
args.putStringArrayList(EXTRA_NAMES, names);
setArguments(args);
}
public void updatePaddings() {
if (listView != null && (expandingEnabled || fullScreenLayoutEnabled)) {
int actionBarHeight = obtainActionBarHeight(activity);
int statusBarHeight = statusBar.getHeight();
int bottomNavigationBarHeight = navigationBar.getBottom();
int rightNavigationBarHeight = navigationBar.getRight();
setNewPadding((View) listView.getParent(), 0, 0, rightNavigationBarHeight, 0);
setNewPadding(listView, KEEP, statusBarHeight + actionBarHeight, KEEP, bottomNavigationBarHeight);
if (actionModeView != null) {
((ViewGroup.MarginLayoutParams) actionModeView.getLayoutParams()).rightMargin =
rightNavigationBarHeight;
}
if (additionalViews != null) {
for (LinkedHashMap.Entry<View, Boolean> additional : additionalViews.entrySet()) {
additional.getKey().setPadding(0, statusBarHeight + (additional.getValue() ? actionBarHeight : 0),
rightNavigationBarHeight, bottomNavigationBarHeight);
}
}
if (drawerListView != null) {
int paddingTop = C.API_LOLLIPOP && drawerOverToolbarEnabled && toolbarView != null
? statusBarHeight : statusBarHeight + actionBarHeight;
if (drawerHeader != null) {
setNewPadding(drawerHeader, KEEP, paddingTop, KEEP, KEEP);
setNewPadding(drawerListView, KEEP, 0, KEEP, bottomNavigationBarHeight);
} else {
setNewPadding(drawerListView, KEEP, paddingTop, KEEP, bottomNavigationBarHeight);
}
}
if (contentForeground != null) {
contentForeground.invalidateSelf();
}
if (statusBarContentForeground != null) {
statusBarContentForeground.invalidateSelf();
}
if (statusBarDrawerForeground != null) {
statusBarDrawerForeground.invalidateSelf();
}
}
}
public final ArrayList<String> getChanHosts(boolean confiruableOnly) {
if (confiruableOnly) {
ArrayList<String> hosts = new ArrayList<>();
for (LinkedHashMap.Entry<String, Integer> entry : this.hosts.entrySet()) {
if (entry.getValue() == HOST_TYPE_CONFIGURABLE) {
hosts.add(entry.getKey());
}
}
return hosts;
} else {
return new ArrayList<>(hosts.keySet());
}
}
public final String getPreferredHost() {
String host = Preferences.getDomainUnhandled(getChanName());
if (StringUtils.isEmpty(host)) {
for (LinkedHashMap.Entry<String, Integer> entry : hosts.entrySet()) {
if (entry.getValue() == HOST_TYPE_CONFIGURABLE) {
host = entry.getKey();
break;
}
}
}
return host;
}
/** 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;
}
/** 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;
}
@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);
}