Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * 
 */
package timeflow.format.field;
 
import timeflow.model.Display;
 
public class FormatStringArray extends FieldFormat
{
   @Override
   public String format(Object o) {
       return Display.arrayToString((String[])o);
   }
 
   @Override
   public Object _parse(String s) {
       return parseList(s);
   }    
   
   public static String[] parseList(String s)
   {
       String[] t= s.length()==0 ? new String[0] : s.split(",");
       for (int i=0; i<t.length; i++)
           t[i]=t[i].trim();
       return t;
   }
   
   public String feedback() 
   {
       if (lastValue==null)
           return "Couldn't understand";
       String[] s=(String[])lastValue;
       if (s.length==0)
           return "Empty list";
       if (s.length==1)
           return "One item";
       return s.length+" items";
   }
 
   @Override
   public Class getType() {
       return String[].class;
   }    
 
   @Override
   public double scoreFormatMatch(String s) {
       double commas=-1;
       for (int i=s.length()-1; i>=0; i--)
           if (s.charAt(i)==',')
               commas++;
       return commas/s.length();
   }
 
   @Override
   public String getHumanName() {
       return "List";
   }
 
}