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
package timeflow.format.field;
 
import timeflow.data.time.*;
import timeflow.util.*;
 
import java.net.URL;
import java.util.*;
 
public class FieldFormatCatalog {
 
   private static Map<String, FieldFormat> formatTable=new HashMap<String, FieldFormat>();
   private static Map<Class, FieldFormat> classTable=new HashMap<Class, FieldFormat>();
 
   static
   {
       for (FieldFormat f: listFormats())
       {
           formatTable.put(f.getHumanName(), f);
           classTable.put(f.getType(), f);
       }
   }
   
   static FieldFormat[] listFormats()
   {
       return new FieldFormat[] {new FormatDateTime(), new FormatString(),
               new FormatStringArray(), new FormatDouble(), new FormatURL()};
   }
   
   public static Iterable<String> classNames()
   {
       return formatTable.keySet();
   }
   
   public static String humanName(Class c){
       return getFormat(c).getHumanName();
   }
   
 
   public static FieldFormat getFormat(Class c) {
       FieldFormat f= classTable.get(c);
       if (f==null)
           System.out.println("Warning: no FieldFormat for "+c);
       return f;
   }
 
   
   public static Class javaClass(String humanName)
   {
       Class  c=formatTable.get(humanName).getType();
       if (c==null)
           System.out.println("Warning: no class for "+humanName);
       return c;
   }
}