mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Add functional value
This commit is contained in:
parent
9d57a38823
commit
1d8a8d7ccf
@ -0,0 +1,69 @@
|
|||||||
|
package com.annimon.hotarufx.lib;
|
||||||
|
|
||||||
|
import com.annimon.hotarufx.exceptions.TypeException;
|
||||||
|
import java.util.Objects;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class FunctionValue implements Value {
|
||||||
|
|
||||||
|
public static final FunctionValue EMPTY = new FunctionValue(args -> NumberValue.ZERO);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Function value;
|
||||||
|
|
||||||
|
public FunctionValue(Function value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int type() {
|
||||||
|
return Types.FUNCTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object raw() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int asInt() {
|
||||||
|
throw new TypeException("Cannot cast function to integer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double asNumber() {
|
||||||
|
throw new TypeException("Cannot cast function to number");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 71 * hash + Objects.hashCode(this.value);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
final FunctionValue other = (FunctionValue) obj;
|
||||||
|
return Objects.equals(this.value, other.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Value o) {
|
||||||
|
return asString().compareTo(o.asString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return asString();
|
||||||
|
}
|
||||||
|
}
|
@ -8,5 +8,6 @@ public class Types {
|
|||||||
STRING = 2,
|
STRING = 2,
|
||||||
MAP = 3,
|
MAP = 3,
|
||||||
NODE = 4,
|
NODE = 4,
|
||||||
FUNCTION = 5;
|
PROPERTY = 5,
|
||||||
|
FUNCTION = 6;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user