2023-01-20 18:52:57 +01:00
|
|
|
package io.gitlab.jfronny.muscript.data.dynamic;
|
2022-06-03 19:54:31 +02:00
|
|
|
|
2023-04-18 14:07:28 +02:00
|
|
|
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
|
|
|
|
import io.gitlab.jfronny.muscript.ast.dynamic.ObjectLiteral;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
|
2023-06-29 15:40:45 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2023-03-12 15:28:44 +01:00
|
|
|
|
2022-06-29 15:41:44 +02:00
|
|
|
import java.util.Map;
|
2023-04-18 14:07:28 +02:00
|
|
|
import java.util.stream.Collectors;
|
2022-06-03 19:54:31 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
public non-sealed interface DObject extends Dynamic<Map<String, Dynamic<?>>> {
|
2023-06-29 15:40:45 +02:00
|
|
|
default @NotNull Dynamic<?> get(String key) {
|
|
|
|
return Dynamic.fromNullable(getValue().get(key));
|
2022-06-03 19:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default boolean has(String key) {
|
|
|
|
return getValue().containsKey(key);
|
|
|
|
}
|
2023-03-12 15:28:44 +01:00
|
|
|
|
|
|
|
@Override
|
2023-04-18 14:07:28 +02:00
|
|
|
default DynamicExpr toExpr() {
|
|
|
|
return new ObjectLiteral(CodeLocation.NONE, getValue().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, s -> s.getValue().toExpr().asDynamicExpr())));
|
2023-03-12 15:28:44 +01:00
|
|
|
}
|
2022-06-03 19:54:31 +02:00
|
|
|
}
|