Skip to content

Commit 336589f

Browse files
committed
Improve map iteration in methods pick and omit.
1 parent 724e5d4 commit 336589f

File tree

1 file changed

+16
-16
lines changed
  • src/main/java/com/github/underscore

1 file changed

+16
-16
lines changed

src/main/java/com/github/underscore/$.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,11 +1330,11 @@ public static <E> E findLastKey(final E[] array, final Predicate<E> pred) {
13301330
}
13311331

13321332
public static <K, V> List<Tuple<K, V>> pick(final Map<K, V> object, final V ... keys) {
1333-
return without(map(newArrayList(object.keySet()), new Function1<K, Tuple<K, V>>() {
1333+
return without(map(newArrayList(object.entrySet()), new Function1<Map.Entry<K, V>, Tuple<K, V>>() {
13341334
@Override
1335-
public Tuple<K, V> apply(K key) {
1336-
if (Arrays.asList(keys).contains(key)) {
1337-
return Tuple.create(key, object.get(key));
1335+
public Tuple<K, V> apply(Map.Entry<K, V> entry) {
1336+
if (Arrays.asList(keys).contains(entry.getKey())) {
1337+
return Tuple.create(entry.getKey(), entry.getValue());
13381338
} else {
13391339
return null;
13401340
}
@@ -1343,11 +1343,11 @@ public Tuple<K, V> apply(K key) {
13431343
}
13441344

13451345
public static <K, V> List<Tuple<K, V>> pick(final Map<K, V> object, final Predicate<V> pred) {
1346-
return without(map(newArrayList(object.keySet()), new Function1<K, Tuple<K, V>>() {
1346+
return without(map(newArrayList(object.entrySet()), new Function1<Map.Entry<K, V>, Tuple<K, V>>() {
13471347
@Override
1348-
public Tuple<K, V> apply(K key) {
1349-
if (pred.apply(object.get(key))) {
1350-
return Tuple.create(key, object.get(key));
1348+
public Tuple<K, V> apply(Map.Entry<K, V> entry) {
1349+
if (pred.apply(object.get(entry.getKey()))) {
1350+
return Tuple.create(entry.getKey(), entry.getValue());
13511351
} else {
13521352
return null;
13531353
}
@@ -1356,26 +1356,26 @@ public Tuple<K, V> apply(K key) {
13561356
}
13571357

13581358
public static <K, V> List<Tuple<K, V>> omit(final Map<K, V> object, final V ... keys) {
1359-
return without(map(newArrayList(object.keySet()), new Function1<K, Tuple<K, V>>() {
1359+
return without(map(newArrayList(object.entrySet()), new Function1<Map.Entry<K, V>, Tuple<K, V>>() {
13601360
@Override
1361-
public Tuple<K, V> apply(K key) {
1362-
if (Arrays.asList(keys).contains(key)) {
1361+
public Tuple<K, V> apply(Map.Entry<K, V> entry) {
1362+
if (Arrays.asList(keys).contains(entry.getKey())) {
13631363
return null;
13641364
} else {
1365-
return Tuple.create(key, object.get(key));
1365+
return Tuple.create(entry.getKey(), entry.getValue());
13661366
}
13671367
}
13681368
}), (Tuple<K, V>) null);
13691369
}
13701370

13711371
public static <K, V> List<Tuple<K, V>> omit(final Map<K, V> object, final Predicate<V> pred) {
1372-
return without(map(newArrayList(object.keySet()), new Function1<K, Tuple<K, V>>() {
1372+
return without(map(newArrayList(object.entrySet()), new Function1<Map.Entry<K, V>, Tuple<K, V>>() {
13731373
@Override
1374-
public Tuple<K, V> apply(K key) {
1375-
if (pred.apply(object.get(key))) {
1374+
public Tuple<K, V> apply(Map.Entry<K, V> entry) {
1375+
if (pred.apply(entry.getValue())) {
13761376
return null;
13771377
} else {
1378-
return Tuple.create(key, object.get(key));
1378+
return Tuple.create(entry.getKey(), entry.getValue());
13791379
}
13801380
}
13811381
}), (Tuple<K, V>) null);

0 commit comments

Comments
 (0)