lphy.base.function.Concat2Str 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;
import java.util.Objects;
public class Concat2Str extends DeterministicFunction {
public static final String firstParamName = "prefix";
public static final String secondParamName = "suffix";
public Concat2Str(@ParameterInfo(name = firstParamName, description ="the prefix substring to concatenate.")
Value substr1,
@ParameterInfo(name = secondParamName, description ="the suffix substring to concatenate.")
Value substr2) {
setParam(firstParamName, substr1);
setParam(secondParamName, substr2);
}
@Override
@GeneratorInfo(name = "concat2Str", description = "A function to concatenate substrings into one sting.")
public Value apply() {
Value substr1 = getParams().get(firstParamName);
Value substr2 = getParams().get(secondParamName);
return join(substr1,substr2);
}
// concatenate Value[] into Value
private Value join(Value... substr) {
StringBuilder oneStr = new StringBuilder();
for (Value s : substr)
oneStr.append(Objects.requireNonNull(s).value());
return new Value(oneStr.toString(), this);
}
}