mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Добавлен метод ifPresent для MapValue
This commit is contained in:
parent
c9249e8577
commit
07fd22914b
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user