Line | |
---|
1 | package tudelft.mentalhealth.perfectfit.updatefuncs;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.util.Arrays;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
9 |
|
---|
10 | import tudelft.dialogmanager.parameters.DoubleValue;
|
---|
11 | import tudelft.dialogmanager.parameters.Parameters;
|
---|
12 | import tudelft.dialogmanager.updatefunctions.UpdateFunction;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Function to get length of a param.
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class StringLength implements UpdateFunction {
|
---|
19 | private String paramname;
|
---|
20 | private String lengthname;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * @param paramname the name of the param to get string length of.
|
---|
24 | * @param lengthname the name of the param to put the length in
|
---|
25 | */
|
---|
26 | @JsonCreator
|
---|
27 | public StringLength(@JsonProperty("paramname") String paramname,
|
---|
28 | @JsonProperty("lengthname") String lengthname) throws IOException {
|
---|
29 | this.paramname = paramname;
|
---|
30 | this.lengthname = lengthname;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Parameters call(Parameters parameters) {
|
---|
35 | return parameters.with(lengthname, new DoubleValue(
|
---|
36 | (double) parameters.get(paramname).toString().length()));
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public List<String> getAssignedParameters() {
|
---|
41 | return Arrays.asList(lengthname);
|
---|
42 | }
|
---|
43 |
|
---|
44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.