Normand Briere
2018-12-17 86f4e9c75951153ae9825f4772633e45698cb602
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
60
61
62
63
64
65
66
67
68
package timeflow.format.field;
 
import java.net.URL;
 
import timeflow.data.time.*;
 
public abstract class FieldFormat
{
        protected String lastInput;
        protected Object lastValue;
        protected boolean understood = true;
        double value;
 
        void add(double x)
        {
                value += x;
        }
 
        void note(String s)
        {
                add(scoreFormatMatch(s));
        }
 
        protected abstract Object _parse(String s) throws Exception;
 
        public abstract String format(Object o);
 
        public abstract Class getType();
 
        public abstract double scoreFormatMatch(String s);
 
        public abstract String getHumanName();
 
        public void setValue(Object o)
        {
                lastValue = o;
                lastInput = o == null ? "" : format(o);
        }
 
        public Object parse(String s) throws Exception
        {
                lastInput = s;
                lastValue = null;
                understood = false;
                lastValue = _parse(s);
                understood = true;
                return lastValue;
        }
 
        public Object getLastValue()
        {
                return lastValue;
        }
 
        public String feedback()
        {
                if (!understood)
                {
                        return "Couldn't understand";
                }
                return lastValue == null ? "(missing)" : "Read: " + format(lastValue);
        }
 
        public boolean isUnderstood()
        {
                return understood;
        }
}