Добавлен метод ifPresent для MapValue

This commit is contained in:
Victor 2016-08-02 21:29:41 +03:00
parent c9249e8577
commit 07fd22914b

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
/**
*
@ -31,6 +32,18 @@ public class MapValue implements Value, Iterable<Map.Entry<Value, Value>> {
this.map = map;
}
public boolean ifPresent(String key, Consumer<Value> consumer) {
return ifPresent(new StringValue(key), consumer);
}
public boolean ifPresent(Value key, Consumer<Value> consumer) {
if (map.containsKey(key)) {
consumer.accept(map.get(key));
return true;
}
return false;
}
public ArrayValue toPairs() {
final int size = map.size();
final ArrayValue result = new ArrayValue(size);