lphy.base.function.Map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lphy-base Show documentation
Show all versions of lphy-base Show documentation
The standard library of LPhy, which contains the required generative distributions and basic functions.
The newest version!
package lphy.base.function;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;
//lphy.parser.functions.MapValue
//replaced by lphy.core.parser.function.MapFunction
@Deprecated
public class Map extends DeterministicFunction> {
final String keysParamName;
final String valuesParamName;
public Map(@ParameterInfo(name = "keys", description = "the keys of the map as an array") Value keys,
@ParameterInfo(name = "values", description = "the values of the map as an array") Value values) {
keysParamName = getParamName(0);
valuesParamName = getParamName(1);
setParam(keysParamName, keys);
setParam(valuesParamName, values);
}
@GeneratorInfo(name="map",description = "A map defined by parallel arrays of keys and values")
public Value> apply() {
Value keys = (Value)getParams().get(keysParamName);
Value values = (Value)getParams().get(valuesParamName);
K[] k = keys.value();
V[] v = values.value();
java.util.Map map = new java.util.HashMap<>();
for (int i = 0; i < k.length; i++) {
map.put(k[i], v[i]);
}
return new Value<>(null, map, this);
}
}