]> gerrit.simantics Code Review - simantics/platform.git/blob
e47cbe8397117e90db194acd67b1e24cf5c067c9
[simantics/platform.git] /
1 package org.simantics.spreadsheet.graph.formula;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import org.apache.poi.util.Internal;
6 import org.simantics.databoard.binding.mutable.Variant;
7
8 public enum FormulaError2{
9         @Internal
10         _NO_ERROR(-1, "(no error)"),NULL(0x00, "#NULL"),DIV0(0x07,"#DIV/0!"),VALUE(0x0F,
11         "#VALUE!"),REF(0x17,"#REF!"),NAME(0x1D,"#NAME?"),NUM(0x24,"#NUM!"),NA(0x2A, "#N/A"),
12         CIRCULAR_REF(0xFFFFFFC4, "~CIRCULAR~REF~"),FUNCTION_NOT_IMPLEMENTED(0xFFFFFFE2,"~FUNCTION~NOT~IMPLEMENTED~");
13         
14         private final String text;
15         //private final Integer longType;
16         //private final byte shortType;
17         
18         private static Map<String, FormulaError2> smap = new HashMap<String, FormulaError2>();
19         
20         private FormulaError2(int type, String text){
21                 //this.longType = type;
22                 //this.shortType = (byte)type;
23                 this.text = text;
24         }
25         
26         static {
27                 for(FormulaError2 error : values()) {
28                         smap.put(error.getString(), error);
29                 }
30         }
31         
32         public String getString(){
33                 return this.text;
34         }
35         
36         public static FormulaError2 forString(String errorName){
37         FormulaError2 err = smap.get(errorName);
38         return err;
39     }
40         
41         public static FormulaError2 forObject(Object errorObj){
42                 if(errorObj instanceof Variant)
43                         return forString(((Variant)errorObj).getValue().toString());
44                 else
45                         return forString(errorObj.toString());
46         }
47         
48         public static String handleErrorCall(Object value){
49                 if(value==null) return VALUE.getString();
50                 FormulaError2 error = FormulaError2.forObject(value);
51                 if(error!=null) return error.getString();
52                 return VALUE.getString();
53         }
54 }