Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.poi.ss.formula.ptg; |
18 |
package org.apache.poi.ss.formula.ptg; |
19 |
|
19 |
|
20 |
import org.apache.poi.ss.usermodel.ErrorConstants; |
20 |
import java.util.HashMap; |
|
|
21 |
import java.util.Map; |
22 |
|
23 |
import org.apache.poi.ss.usermodel.FormulaError; |
21 |
import org.apache.poi.util.LittleEndianInput; |
24 |
import org.apache.poi.util.LittleEndianInput; |
22 |
import org.apache.poi.util.LittleEndianOutput; |
25 |
import org.apache.poi.util.LittleEndianOutput; |
23 |
|
26 |
|
Lines 26-68
Link Here
|
26 |
*/ |
29 |
*/ |
27 |
public final class ErrPtg extends ScalarConstantPtg { |
30 |
public final class ErrPtg extends ScalarConstantPtg { |
28 |
|
31 |
|
29 |
// convenient access to namespace |
|
|
30 |
private static final ErrorConstants EC = null; |
31 |
|
32 |
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */ |
32 |
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */ |
33 |
@SuppressWarnings("static-access") |
33 |
public static final ErrPtg NULL_INTERSECTION = new ErrPtg(FormulaError.NULL); |
34 |
public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL); |
34 |
|
35 |
/** <b>#DIV/0!</b> - Division by zero */ |
35 |
/** <b>#DIV/0!</b> - Division by zero */ |
36 |
@SuppressWarnings("static-access") |
36 |
public static final ErrPtg DIV_ZERO = new ErrPtg(FormulaError.DIV0); |
37 |
public static final ErrPtg DIV_ZERO = new ErrPtg(EC.ERROR_DIV_0); |
37 |
|
38 |
/** <b>#VALUE!</b> - Wrong type of operand */ |
38 |
/** <b>#VALUE!</b> - Wrong type of operand */ |
39 |
@SuppressWarnings("static-access") |
39 |
public static final ErrPtg VALUE_INVALID = new ErrPtg(FormulaError.VALUE); |
40 |
public static final ErrPtg VALUE_INVALID = new ErrPtg(EC.ERROR_VALUE); |
40 |
|
41 |
/** <b>#REF!</b> - Illegal or deleted cell reference */ |
41 |
/** <b>#REF!</b> - Illegal or deleted cell reference */ |
42 |
@SuppressWarnings("static-access") |
42 |
public static final ErrPtg REF_INVALID = new ErrPtg(FormulaError.REF); |
43 |
public static final ErrPtg REF_INVALID = new ErrPtg(EC.ERROR_REF); |
43 |
|
44 |
/** <b>#NAME?</b> - Wrong function or range name */ |
44 |
/** <b>#NAME?</b> - Wrong function or range name */ |
45 |
@SuppressWarnings("static-access") |
45 |
public static final ErrPtg NAME_INVALID = new ErrPtg(FormulaError.NAME); |
46 |
public static final ErrPtg NAME_INVALID = new ErrPtg(EC.ERROR_NAME); |
46 |
|
47 |
/** <b>#NUM!</b> - Value range overflow */ |
47 |
/** <b>#NUM!</b> - Value range overflow */ |
48 |
@SuppressWarnings("static-access") |
48 |
public static final ErrPtg NUM_ERROR = new ErrPtg(FormulaError.NUM); |
49 |
public static final ErrPtg NUM_ERROR = new ErrPtg(EC.ERROR_NUM); |
49 |
|
50 |
/** <b>#N/A</b> - Argument or function not available */ |
50 |
/** <b>#N/A</b> - Argument or function not available */ |
51 |
@SuppressWarnings("static-access") |
51 |
public static final ErrPtg N_A = new ErrPtg(FormulaError.NA); |
52 |
public static final ErrPtg N_A = new ErrPtg(EC.ERROR_NA); |
52 |
|
53 |
|
53 |
private static Map<Byte, ErrPtg> bmap = new HashMap<Byte, ErrPtg>(); |
54 |
|
54 |
static { |
|
|
55 |
bmap.put(FormulaError.NULL.getCode(), NULL_INTERSECTION); |
56 |
bmap.put(FormulaError.DIV0.getCode(), DIV_ZERO); |
57 |
bmap.put(FormulaError.VALUE.getCode(), VALUE_INVALID); |
58 |
bmap.put(FormulaError.REF.getCode(), REF_INVALID); |
59 |
bmap.put(FormulaError.NAME.getCode(), NAME_INVALID); |
60 |
bmap.put(FormulaError.NUM.getCode(), NUM_ERROR); |
61 |
bmap.put(FormulaError.NA.getCode(), N_A); |
62 |
} |
63 |
|
55 |
public static final short sid = 0x1c; |
64 |
public static final short sid = 0x1c; |
56 |
private static final int SIZE = 2; |
65 |
private static final int SIZE = 2; |
57 |
private final int field_1_error_code; |
66 |
private final int field_1_error_code; |
58 |
|
67 |
|
59 |
/** Creates new ErrPtg */ |
68 |
/** Creates new ErrPtg */ |
60 |
|
69 |
private ErrPtg(FormulaError error) { |
61 |
private ErrPtg(int errorCode) { |
70 |
field_1_error_code = error.getCode(); |
62 |
if(!ErrorConstants.isValidCode(errorCode)) { |
|
|
63 |
throw new IllegalArgumentException("Invalid error code (" + errorCode + ")"); |
64 |
} |
65 |
field_1_error_code = errorCode; |
66 |
} |
71 |
} |
67 |
|
72 |
|
68 |
public static ErrPtg read(LittleEndianInput in) { |
73 |
public static ErrPtg read(LittleEndianInput in) { |
Lines 75-81
Link Here
|
75 |
} |
80 |
} |
76 |
|
81 |
|
77 |
public String toFormulaString() { |
82 |
public String toFormulaString() { |
78 |
return ErrorConstants.getText(field_1_error_code); |
83 |
return FormulaError.forInt(field_1_error_code).getString(); |
79 |
} |
84 |
} |
80 |
|
85 |
|
81 |
public int getSize() { |
86 |
public int getSize() { |
Lines 87-101
Link Here
|
87 |
} |
92 |
} |
88 |
|
93 |
|
89 |
public static ErrPtg valueOf(int code) { |
94 |
public static ErrPtg valueOf(int code) { |
90 |
switch(code) { |
95 |
return valueOf((byte) code); |
91 |
case ErrorConstants.ERROR_DIV_0: return DIV_ZERO; |
|
|
92 |
case ErrorConstants.ERROR_NA: return N_A; |
93 |
case ErrorConstants.ERROR_NAME: return NAME_INVALID; |
94 |
case ErrorConstants.ERROR_NULL: return NULL_INTERSECTION; |
95 |
case ErrorConstants.ERROR_NUM: return NUM_ERROR; |
96 |
case ErrorConstants.ERROR_REF: return REF_INVALID; |
97 |
case ErrorConstants.ERROR_VALUE: return VALUE_INVALID; |
98 |
} |
99 |
throw new RuntimeException("Unexpected error code (" + code + ")"); |
100 |
} |
96 |
} |
|
|
97 |
|
98 |
private static ErrPtg valueOf(byte code) { |
99 |
if (bmap.containsKey(code)) |
100 |
return bmap.get(code); |
101 |
else |
102 |
throw new RuntimeException("Unexpected error code (" + code + ")"); |
103 |
} |
101 |
} |
104 |
} |