38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
|
package io.gitlab.jfronny.muscript.dynamic;
|
||
|
|
||
|
import io.gitlab.jfronny.commons.*;
|
||
|
|
||
|
public interface Dynamic<T> {
|
||
|
T getValue();
|
||
|
|
||
|
default DBool asBool() {
|
||
|
if (this instanceof DBool bool) return bool;
|
||
|
else throw new IllegalArgumentException("This value is not a bool");
|
||
|
}
|
||
|
|
||
|
default DNumber asNumber() {
|
||
|
if (this instanceof DNumber number) return number;
|
||
|
else throw new IllegalArgumentException("This value is not a number");
|
||
|
}
|
||
|
|
||
|
default DString asString() {
|
||
|
if (this instanceof DString string) return string;
|
||
|
else return DFinal.of(StringFormatter.toString(getValue()));
|
||
|
}
|
||
|
|
||
|
default DObject asObject() {
|
||
|
if (this instanceof DObject object) return object;
|
||
|
else throw new IllegalArgumentException("This value is not an object");
|
||
|
}
|
||
|
|
||
|
default DList asList() {
|
||
|
if (this instanceof DList list) return list;
|
||
|
else throw new IllegalArgumentException("This value is not a list");
|
||
|
}
|
||
|
|
||
|
default DCallable asCallable() {
|
||
|
if (this instanceof DCallable callable) return callable;
|
||
|
else throw new IllegalArgumentException("This value is not a callable");
|
||
|
}
|
||
|
}
|