You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
import android.os.Bundle;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
class Test {
|
|
|
|
void inefficient_loop_bad(HashMap<String, Integer> testMap) {
|
|
for (String key : testMap.keySet()) {
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_bad(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator itr2 = testMap.keySet().iterator();
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void inefficient_loop_itr_bad_FN(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator itr2 = testMap.keySet().iterator();
|
|
int i = 0;
|
|
while (itr2.hasNext()) {
|
|
String key = (String) itr2.next();
|
|
testMap.get(key);
|
|
}
|
|
}
|
|
|
|
void efficient_loop_itr_ok(HashMap<String, Integer> testMap) {
|
|
|
|
Iterator<Map.Entry<String, Integer>> itr1 = testMap.entrySet().iterator();
|
|
while (itr1.hasNext()) {
|
|
Map.Entry<String, Integer> entry = itr1.next();
|
|
entry.getKey();
|
|
entry.getValue();
|
|
}
|
|
}
|
|
|
|
void efficient_loop_ok(HashMap<String, Integer> testMap) {
|
|
for (Map.Entry<String, Integer> entry : testMap.entrySet()) {
|
|
entry.getKey();
|
|
entry.getValue();
|
|
}
|
|
}
|
|
|
|
void negative_loop_ok(HashMap<String, Integer> testMap1, HashMap<String, Integer> testMap2) {
|
|
for (String key : testMap1.keySet()) {
|
|
testMap2.get(key);
|
|
}
|
|
}
|
|
|
|
// Bundle doesn't implement Map hence have any entrySet
|
|
public void from_bundle_ok(Bundle extras) {
|
|
for (String key : extras.keySet()) {
|
|
Object t = extras.get(key);
|
|
}
|
|
}
|
|
}
|