source: PerfectFit/Dialog/src/main/java/tudelft/mentalhealth/perfectfit/updatefuncs/StringLength.java

Last change on this file was 7, checked in by Wouter Pasman, 9 months ago

#124 release PerfectFit sources

File size: 1.2 KB
Line 
1package tudelft.mentalhealth.perfectfit.updatefuncs;
2
3import java.io.IOException;
4import java.util.Arrays;
5import java.util.List;
6
7import com.fasterxml.jackson.annotation.JsonCreator;
8import com.fasterxml.jackson.annotation.JsonProperty;
9
10import tudelft.dialogmanager.parameters.DoubleValue;
11import tudelft.dialogmanager.parameters.Parameters;
12import tudelft.dialogmanager.updatefunctions.UpdateFunction;
13
14/**
15 * Function to get length of a param.
16 *
17 */
18public 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.