View | Details | Raw Unified | Return to bug 58331
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/usermodel/FormulaError.java (-3 / +22 lines)
Lines 152-157 Link Here
152
        }
152
        }
153
    }
153
    }
154
    
154
    
155
    /**
156
     * @param errorCode  the error code
157
     * @return true if error code is a recognized error code
158
     */
155
    public static final boolean isValidCode(int errorCode) {
159
    public static final boolean isValidCode(int errorCode) {
156
        for (FormulaError error : values()) {
160
        for (FormulaError error : values()) {
157
            if (error.getCode() == errorCode) return true;
161
            if (error.getCode() == errorCode) return true;
Lines 160-170 Link Here
160
        return false;
164
        return false;
161
    }
165
    }
162
166
167
    /**
168
     * @param type  the error code
169
     * @return FormulaError enum corresponding to the error code
170
     * @throws IllegalArgumentException if error code is unrecognized
171
     */
163
    public static FormulaError forInt(byte type){
172
    public static FormulaError forInt(byte type){
164
        FormulaError err = bmap.get(type);
173
        final FormulaError err = bmap.get(type);
165
        if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
174
        if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
166
        return err;
175
        return err;
167
    }
176
    }
177
    /**
178
     * @param type  the error code
179
     * @return FormulaError enum corresponding to the error code
180
     * @throws IllegalArgumentException if error code is unrecognized
181
     */
168
    public static FormulaError forInt(int type){
182
    public static FormulaError forInt(int type){
169
        FormulaError err = imap.get(type);
183
        FormulaError err = imap.get(type);
170
        if(err == null) err = bmap.get((byte)type);
184
        if(err == null) err = bmap.get((byte)type);
Lines 172-179 Link Here
172
        return err;
186
        return err;
173
    }
187
    }
174
188
175
    public static FormulaError forString(String code){
189
    /**
176
        FormulaError err = smap.get(code);
190
     * @param code  the error code string
191
     * @return FormulaError enum corresponding to the error code
192
     * @throws IllegalArgumentException if error code is unrecognized
193
     */
194
    public static FormulaError forString(String code) throws IllegalArgumentException {
195
        final FormulaError err = smap.get(code);
177
        if(err == null) throw new IllegalArgumentException("Unknown error code: " + code);
196
        if(err == null) throw new IllegalArgumentException("Unknown error code: " + code);
178
        return err;
197
        return err;
179
    }
198
    }
(-)src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java (-16 / +10 lines)
Lines 18-23 Link Here
18
package org.apache.poi.ss.formula.constant;
18
package org.apache.poi.ss.formula.constant;
19
19
20
import org.apache.poi.ss.usermodel.ErrorConstants;
20
import org.apache.poi.ss.usermodel.ErrorConstants;
21
import org.apache.poi.ss.usermodel.FormulaError;
21
import org.apache.poi.util.POILogFactory;
22
import org.apache.poi.util.POILogFactory;
22
import org.apache.poi.util.POILogger;
23
import org.apache.poi.util.POILogger;
23
/**
24
/**
Lines 26-52 Link Here
26
 * This class is a type-safe wrapper for a 16-bit int value performing a similar job to 
27
 * This class is a type-safe wrapper for a 16-bit int value performing a similar job to 
27
 * <tt>ErrorEval</tt>.
28
 * <tt>ErrorEval</tt>.
28
 * 
29
 * 
30
 * @deprecated Use {@link FormulaError} instead where possible
31
 * 
29
 * @author Josh Micich
32
 * @author Josh Micich
30
 */
33
 */
31
public class ErrorConstant {
34
public class ErrorConstant {
32
	private static POILogger logger = POILogFactory.getLogger(ErrorConstant.class);
35
	private static POILogger logger = POILogFactory.getLogger(ErrorConstant.class);
33
	// convenient access to name space
34
	private static final ErrorConstants EC = null;
35
36
36
	@SuppressWarnings("static-access")
37
	private static final ErrorConstant NULL = new ErrorConstant(ErrorConstants.ERROR_NULL);
37
    private static final ErrorConstant NULL = new ErrorConstant(EC.ERROR_NULL);
38
	private static final ErrorConstant DIV_0 = new ErrorConstant(ErrorConstants.ERROR_DIV_0);
38
	@SuppressWarnings("static-access")
39
	private static final ErrorConstant VALUE = new ErrorConstant(ErrorConstants.ERROR_VALUE);
39
    private static final ErrorConstant DIV_0 = new ErrorConstant(EC.ERROR_DIV_0);
40
	private static final ErrorConstant REF = new ErrorConstant(ErrorConstants.ERROR_REF);
40
	@SuppressWarnings("static-access")
41
	private static final ErrorConstant NAME = new ErrorConstant(ErrorConstants.ERROR_NAME);
41
    private static final ErrorConstant VALUE = new ErrorConstant(EC.ERROR_VALUE);
42
	private static final ErrorConstant NUM = new ErrorConstant(ErrorConstants.ERROR_NUM);
42
	@SuppressWarnings("static-access")
43
	private static final ErrorConstant NA = new ErrorConstant(ErrorConstants.ERROR_NA);
43
    private static final ErrorConstant REF = new ErrorConstant(EC.ERROR_REF);
44
	@SuppressWarnings("static-access")
45
    private static final ErrorConstant NAME = new ErrorConstant(EC.ERROR_NAME);
46
	@SuppressWarnings("static-access")
47
    private static final ErrorConstant NUM = new ErrorConstant(EC.ERROR_NUM);
48
	@SuppressWarnings("static-access")
49
    private static final ErrorConstant NA = new ErrorConstant(EC.ERROR_NA);
50
44
51
	private final int _errorCode;
45
	private final int _errorCode;
52
46
(-)src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java (-2 / +2 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class NotEqualPtg extends ValueOperatorPtg {
25
public final class NotEqualPtg extends ValueOperatorPtg {
26
    public final static byte sid = 0x0e;
26
    public final static byte sid = 0x0e;
27
    private final static String NOT_EQUAL = "<>";
27
28
28
    public static final ValueOperatorPtg instance = new NotEqualPtg();
29
    public static final ValueOperatorPtg instance = new NotEqualPtg();
29
30
Lines 43-50 Link Here
43
        StringBuffer buffer = new StringBuffer();
44
        StringBuffer buffer = new StringBuffer();
44
45
45
        buffer.append( operands[0] );
46
        buffer.append( operands[0] );
46
47
        buffer.append(NOT_EQUAL);
47
        buffer.append("<>");
48
        buffer.append( operands[1] );
48
        buffer.append( operands[1] );
49
49
50
        return buffer.toString();
50
        return buffer.toString();
(-)src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java (-2 / +3 lines)
Lines 25-30 Link Here
25
 */
25
 */
26
public final class UnionPtg extends OperationPtg {
26
public final class UnionPtg extends OperationPtg {
27
    public final static byte sid  = 0x10;
27
    public final static byte sid  = 0x10;
28
    private final static String UNION = ",";
28
29
29
    public static final OperationPtg instance = new UnionPtg();
30
    public static final OperationPtg instance = new UnionPtg();
30
31
Lines 47-53 Link Here
47
48
48
    public String toFormulaString()
49
    public String toFormulaString()
49
    {
50
    {
50
        return ",";
51
        return UNION;
51
    }
52
    }
52
53
53
54
Lines 57-63 Link Here
57
         StringBuffer buffer = new StringBuffer();
58
         StringBuffer buffer = new StringBuffer();
58
59
59
         buffer.append(operands[ 0 ]);
60
         buffer.append(operands[ 0 ]);
60
         buffer.append(",");
61
         buffer.append(UNION);
61
         buffer.append(operands[ 1 ]);
62
         buffer.append(operands[ 1 ]);
62
         return buffer.toString();
63
         return buffer.toString();
63
     }
64
     }
(-)src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java (-3 / +3 lines)
Lines 18-24 Link Here
18
package org.apache.poi.ss.formula.ptg;
18
package org.apache.poi.ss.formula.ptg;
19
19
20
import org.apache.poi.ss.formula.SheetNameFormatter;
20
import org.apache.poi.ss.formula.SheetNameFormatter;
21
import org.apache.poi.ss.usermodel.ErrorConstants;
21
import org.apache.poi.ss.usermodel.FormulaError;
22
import org.apache.poi.util.LittleEndianOutput;
22
import org.apache.poi.util.LittleEndianOutput;
23
23
24
24
Lines 48-54 Link Here
48
        }
48
        }
49
        sb.append("sheet=").append(getSheetName());
49
        sb.append("sheet=").append(getSheetName());
50
        sb.append(" ! ");
50
        sb.append(" ! ");
51
        sb.append(ErrorConstants.getText(ErrorConstants.ERROR_REF));
51
        sb.append(FormulaError.REF.getString());
52
        sb.append("]");
52
        sb.append("]");
53
        return sb.toString();
53
        return sb.toString();
54
    }
54
    }
Lines 75-81 Link Here
75
            SheetNameFormatter.appendFormat(sb, sheetName);
75
            SheetNameFormatter.appendFormat(sb, sheetName);
76
        }
76
        }
77
        sb.append('!');
77
        sb.append('!');
78
        sb.append(ErrorConstants.getText(ErrorConstants.ERROR_REF));
78
        sb.append(FormulaError.REF.getString());
79
        return sb.toString();
79
        return sb.toString();
80
    }
80
    }
81
    
81
    
(-)src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java (+5 lines)
Lines 17-22 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.SpreadsheetVersion;
20
import org.apache.poi.ss.util.AreaReference;
21
import org.apache.poi.ss.util.AreaReference;
21
import org.apache.poi.util.LittleEndianInput;
22
import org.apache.poi.util.LittleEndianInput;
22
23
Lines 33-41 Link Here
33
	public AreaPtg(LittleEndianInput in)  {
34
	public AreaPtg(LittleEndianInput in)  {
34
		super(in);
35
		super(in);
35
	}
36
	}
37
	@Deprecated
36
	public AreaPtg(String arearef) {
38
	public AreaPtg(String arearef) {
37
		super(new AreaReference(arearef));
39
		super(new AreaReference(arearef));
38
	}
40
	}
41
	public AreaPtg(String arearef, SpreadsheetVersion version) {
42
		super(new AreaReference(arearef, version));
43
	}
39
	public AreaPtg(AreaReference areaRef) {
44
	public AreaPtg(AreaReference areaRef) {
40
		super(areaRef);
45
		super(areaRef);
41
	}
46
	}
(-)src/java/org/apache/poi/ss/formula/ptg/Ptg.java (+10 lines)
Lines 249-254 Link Here
249
	public String toString(){
249
	public String toString(){
250
		return this.getClass().toString();
250
		return this.getClass().toString();
251
	}
251
	}
252
	
253
	@Override
254
	public boolean equals(Object other) {
255
		return (other instanceof Ptg) && toString().equals(other.toString());
256
	}
257
	
258
	@Override
259
	public int hashCode() {
260
		return toString().hashCode();
261
	}
252
262
253
	public static final byte CLASS_REF = 0x00;
263
	public static final byte CLASS_REF = 0x00;
254
	public static final byte CLASS_VALUE = 0x20;
264
	public static final byte CLASS_VALUE = 0x20;
(-)src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java (-2 / +2 lines)
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 org.apache.poi.ss.usermodel.FormulaError;
21
import org.apache.poi.util.LittleEndianInput;
21
import org.apache.poi.util.LittleEndianInput;
22
import org.apache.poi.util.LittleEndianOutput;
22
import org.apache.poi.util.LittleEndianOutput;
23
23
Lines 49-55 Link Here
49
	}
49
	}
50
50
51
	public String toFormulaString() {
51
	public String toFormulaString() {
52
		return ErrorConstants.getText(ErrorConstants.ERROR_REF);
52
		return FormulaError.REF.getString();
53
	}
53
	}
54
54
55
	public byte getDefaultOperandClass() {
55
	public byte getDefaultOperandClass() {
(-)src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java (-2 / +2 lines)
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 org.apache.poi.ss.usermodel.FormulaError;
21
import org.apache.poi.util.LittleEndianInput;
21
import org.apache.poi.util.LittleEndianInput;
22
import org.apache.poi.util.LittleEndianOutput;
22
import org.apache.poi.util.LittleEndianOutput;
23
23
Lines 53-59 Link Here
53
    }
53
    }
54
54
55
    public String toFormulaString() {
55
    public String toFormulaString() {
56
        return ErrorConstants.getText(ErrorConstants.ERROR_REF);
56
        return FormulaError.REF.getString();
57
    }
57
    }
58
    
58
    
59
    public byte getDefaultOperandClass() {
59
    public byte getDefaultOperandClass() {
(-)src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java (-2 / +2 lines)
Lines 18-24 Link Here
18
package org.apache.poi.ss.formula.ptg;
18
package org.apache.poi.ss.formula.ptg;
19
19
20
20
21
import org.apache.poi.ss.usermodel.ErrorConstants;
21
import org.apache.poi.ss.usermodel.FormulaError;
22
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
22
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
23
import org.apache.poi.ss.formula.WorkbookDependentFormula;
23
import org.apache.poi.ss.formula.WorkbookDependentFormula;
24
import org.apache.poi.util.LittleEndianInput;
24
import org.apache.poi.util.LittleEndianInput;
Lines 49-55 Link Here
49
49
50
	public String toFormulaString(FormulaRenderingWorkbook book) {
50
	public String toFormulaString(FormulaRenderingWorkbook book) {
51
		return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, 
51
		return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, 
52
				ErrorConstants.getText(ErrorConstants.ERROR_REF));
52
				FormulaError.REF.getString());
53
	}
53
	}
54
	public String toFormulaString() {
54
	public String toFormulaString() {
55
		throw new RuntimeException("3D references need a workbook to determine formula text");
55
		throw new RuntimeException("3D references need a workbook to determine formula text");
(-)src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java (-3 / +3 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class PowerPtg extends ValueOperatorPtg {
25
public final class PowerPtg extends ValueOperatorPtg {
26
    public final static byte sid  = 0x07;
26
    public final static byte sid  = 0x07;
27
    private final static String POWER = "^";
27
28
28
    public static final ValueOperatorPtg instance = new PowerPtg();
29
    public static final ValueOperatorPtg instance = new PowerPtg();
29
30
Lines 36-50 Link Here
36
    }
37
    }
37
38
38
    public int getNumberOfOperands() {
39
    public int getNumberOfOperands() {
39
        return 2; // TODO - 2 seems wrong (Jun 2008).  Maybe this method is not relevant
40
        return 2;
40
    }
41
    }
41
 
42
 
42
    public String toFormulaString(String[] operands) {
43
    public String toFormulaString(String[] operands) {
43
         StringBuffer buffer = new StringBuffer();
44
         StringBuffer buffer = new StringBuffer();
44
45
45
        
46
        buffer.append(operands[ 0 ]);
46
        buffer.append(operands[ 0 ]);
47
        buffer.append("^");
47
        buffer.append(POWER);
48
        buffer.append(operands[ 1 ]);
48
        buffer.append(operands[ 1 ]);
49
        return buffer.toString();
49
        return buffer.toString();
50
    }       
50
    }       
(-)src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java (+1 lines)
Lines 40-45 Link Here
40
	private int field_1_index_extern_sheet;
40
	private int field_1_index_extern_sheet;
41
41
42
42
43
	@Deprecated
43
	public Area3DPtg(String arearef, int externIdx) {
44
	public Area3DPtg(String arearef, int externIdx) {
44
		super(new AreaReference(arearef));
45
		super(new AreaReference(arearef));
45
		setExternSheetIndex(externIdx);
46
		setExternSheetIndex(externIdx);
(-)src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java (-7 / +16 lines)
Lines 17-22 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.SpreadsheetVersion;
20
import org.apache.poi.ss.formula.SheetIdentifier;
21
import org.apache.poi.ss.formula.SheetIdentifier;
21
import org.apache.poi.ss.formula.SheetNameFormatter;
22
import org.apache.poi.ss.formula.SheetNameFormatter;
22
import org.apache.poi.ss.formula.SheetRangeIdentifier;
23
import org.apache.poi.ss.formula.SheetRangeIdentifier;
Lines 36-44 Link Here
36
    private String firstSheetName;
37
    private String firstSheetName;
37
    private String lastSheetName;
38
    private String lastSheetName;
38
39
39
	public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, String arearef) {
40
    @Deprecated
40
		this(externalWorkbookNumber, sheetName, new AreaReference(arearef));
41
    public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, String arearef) {
41
	}
42
        this(externalWorkbookNumber, sheetName, new AreaReference(arearef));
43
    }
44
    public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, String arearef, SpreadsheetVersion version) {
45
        this(externalWorkbookNumber, sheetName, new AreaReference(arearef, version));
46
    }
42
    public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, AreaReference arearef) {
47
    public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, AreaReference arearef) {
43
        super(arearef);
48
        super(arearef);
44
        this.externalWorkbookNumber = externalWorkbookNumber;
49
        this.externalWorkbookNumber = externalWorkbookNumber;
Lines 50-64 Link Here
50
        }
55
        }
51
    }
56
    }
52
57
58
    @Deprecated
53
    public Area3DPxg(SheetIdentifier sheetName, String arearef) {
59
    public Area3DPxg(SheetIdentifier sheetName, String arearef) {
54
        this(sheetName, new AreaReference(arearef));
60
        this(sheetName, new AreaReference(arearef));
55
    }
61
    }
62
    public Area3DPxg(SheetIdentifier sheetName, String arearef, SpreadsheetVersion version) {
63
        this(sheetName, new AreaReference(arearef, version));
64
    }
56
    public Area3DPxg(SheetIdentifier sheetName, AreaReference arearef) {
65
    public Area3DPxg(SheetIdentifier sheetName, AreaReference arearef) {
57
        this(-1, sheetName, arearef);
66
        this(-1, sheetName, arearef);
58
    }
67
    }
59
68
60
	@Override
69
    @Override
61
	public String toString() {
70
    public String toString() {
62
        StringBuffer sb = new StringBuffer();
71
        StringBuffer sb = new StringBuffer();
63
        sb.append(getClass().getName());
72
        sb.append(getClass().getName());
64
        sb.append(" [");
73
        sb.append(" [");
Lines 76-83 Link Here
76
        sb.append(formatReferenceAsString());
85
        sb.append(formatReferenceAsString());
77
        sb.append("]");
86
        sb.append("]");
78
        return sb.toString();
87
        return sb.toString();
79
	}
88
    }
80
	
89
81
    public int getExternalWorkbookNumber() {
90
    public int getExternalWorkbookNumber() {
82
        return externalWorkbookNumber;
91
        return externalWorkbookNumber;
83
    }
92
    }
(-)src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java (-2 / +3 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class IntersectionPtg extends OperationPtg {
25
public final class IntersectionPtg extends OperationPtg {
26
	public final static byte sid = 0x0f;
26
	public final static byte sid = 0x0f;
27
	public final static String INTERSECTION = " ";
27
28
28
	public static final OperationPtg instance = new IntersectionPtg();
29
	public static final OperationPtg instance = new IntersectionPtg();
29
30
Lines 44-57 Link Here
44
	}
45
	}
45
46
46
	public String toFormulaString() {
47
	public String toFormulaString() {
47
		return " ";
48
		return INTERSECTION;
48
	}
49
	}
49
50
50
	public String toFormulaString(String[] operands) {
51
	public String toFormulaString(String[] operands) {
51
		StringBuffer buffer = new StringBuffer();
52
		StringBuffer buffer = new StringBuffer();
52
53
53
		buffer.append(operands[0]);
54
		buffer.append(operands[0]);
54
		buffer.append(" ");
55
		buffer.append(INTERSECTION);
55
		buffer.append(operands[1]);
56
		buffer.append(operands[1]);
56
		return buffer.toString();
57
		return buffer.toString();
57
	}
58
	}
(-)src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java (-2 / +2 lines)
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 org.apache.poi.ss.usermodel.FormulaError;
21
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
21
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
22
import org.apache.poi.ss.formula.WorkbookDependentFormula;
22
import org.apache.poi.ss.formula.WorkbookDependentFormula;
23
import org.apache.poi.util.LittleEndianInput;
23
import org.apache.poi.util.LittleEndianInput;
Lines 49-55 Link Here
49
	}
49
	}
50
	public String toFormulaString(FormulaRenderingWorkbook book) {
50
	public String toFormulaString(FormulaRenderingWorkbook book) {
51
		return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, 
51
		return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, 
52
				ErrorConstants.getText(ErrorConstants.ERROR_REF));
52
				FormulaError.REF.getString());
53
	}
53
	}
54
	public String toFormulaString() {
54
	public String toFormulaString() {
55
		throw new RuntimeException("3D references need a workbook to determine formula text");
55
		throw new RuntimeException("3D references need a workbook to determine formula text");
(-)src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java (-37 / +40 lines)
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
}
(-)src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java (-1 / +2 lines)
Lines 23-28 Link Here
23
 */
23
 */
24
public final class EqualPtg extends ValueOperatorPtg {
24
public final class EqualPtg extends ValueOperatorPtg {
25
    public final static byte sid  = 0x0b;
25
    public final static byte sid  = 0x0b;
26
    private final static String EQUAL = "=";
26
27
27
    public static final ValueOperatorPtg instance = new EqualPtg();
28
    public static final ValueOperatorPtg instance = new EqualPtg();
28
29
Lines 43-49 Link Here
43
44
44
        
45
        
45
        buffer.append(operands[ 0 ]);
46
        buffer.append(operands[ 0 ]);
46
        buffer.append("=");
47
        buffer.append(EQUAL);
47
        buffer.append(operands[ 1 ]);
48
        buffer.append(operands[ 1 ]);
48
        return buffer.toString();
49
        return buffer.toString();
49
    }       
50
    }       
(-)src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java (-2 / +2 lines)
Lines 26-31 Link Here
26
public final class GreaterEqualPtg extends ValueOperatorPtg {
26
public final class GreaterEqualPtg extends ValueOperatorPtg {
27
    public final static int  SIZE = 1;
27
    public final static int  SIZE = 1;
28
    public final static byte sid  = 0x0c;
28
    public final static byte sid  = 0x0c;
29
    private final static String GREATER_THAN_OR_EQUAL = ">=";
29
30
30
    public static final ValueOperatorPtg instance = new GreaterEqualPtg();
31
    public static final ValueOperatorPtg instance = new GreaterEqualPtg();
31
32
Lines 45-52 Link Here
45
         StringBuffer buffer = new StringBuffer();
46
         StringBuffer buffer = new StringBuffer();
46
47
47
        buffer.append(operands[ 0 ]);
48
        buffer.append(operands[ 0 ]);
48
49
        buffer.append(GREATER_THAN_OR_EQUAL);
49
        buffer.append(">=");
50
        buffer.append(operands[ 1 ]);
50
        buffer.append(operands[ 1 ]);
51
51
52
        return buffer.toString();
52
        return buffer.toString();
(-)src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java (-2 / +4 lines)
Lines 33-38 Link Here
33
33
34
	private final static int SIZE = 1;
34
	private final static int SIZE = 1;
35
	public final static byte sid = 0x15;
35
	public final static byte sid = 0x15;
36
	private final static String OPEN = "(";
37
	private final static String CLOSE = ")";
36
38
37
	public static final ControlPtg instance = new ParenthesisPtg();
39
	public static final ControlPtg instance = new ParenthesisPtg();
38
40
Lines 49-58 Link Here
49
	}
51
	}
50
52
51
	public String toFormulaString() {
53
	public String toFormulaString() {
52
		return "()";
54
		return OPEN + CLOSE;
53
	}
55
	}
54
56
55
	public String toFormulaString(String[] operands) {
57
	public String toFormulaString(String[] operands) {
56
		return "(" + operands[0] + ")";
58
		return OPEN + operands[0] + CLOSE;
57
	}
59
	}
58
}
60
}
(-)src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java (-1 / +2 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class SubtractPtg extends ValueOperatorPtg {
25
public final class SubtractPtg extends ValueOperatorPtg {
26
    public final static byte sid  = 0x04;
26
    public final static byte sid  = 0x04;
27
    public final static String SUBTRACT = "-";
27
28
28
    public static final ValueOperatorPtg instance = new SubtractPtg();
29
    public static final ValueOperatorPtg instance = new SubtractPtg();
29
30
Lines 43-49 Link Here
43
        StringBuffer buffer = new StringBuffer();
44
        StringBuffer buffer = new StringBuffer();
44
45
45
        buffer.append(operands[ 0 ]);
46
        buffer.append(operands[ 0 ]);
46
        buffer.append("-");
47
        buffer.append(SUBTRACT);
47
        buffer.append(operands[ 1 ]);
48
        buffer.append(operands[ 1 ]);
48
        return buffer.toString();
49
        return buffer.toString();
49
    }
50
    }
(-)src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java (-1 / +2 lines)
Lines 28-33 Link Here
28
 */
28
 */
29
public final class LessEqualPtg extends ValueOperatorPtg {
29
public final class LessEqualPtg extends ValueOperatorPtg {
30
    public final static byte sid = 0x0a;
30
    public final static byte sid = 0x0a;
31
    private final static String LESS_THAN_OR_EQUAL = "<=";
31
32
32
    public static final ValueOperatorPtg instance = new LessEqualPtg();
33
    public static final ValueOperatorPtg instance = new LessEqualPtg();
33
34
Lines 46-52 Link Here
46
    public String toFormulaString(String[] operands) {
47
    public String toFormulaString(String[] operands) {
47
        StringBuffer buffer = new StringBuffer();
48
        StringBuffer buffer = new StringBuffer();
48
        buffer.append( operands[0] );
49
        buffer.append( operands[0] );
49
        buffer.append("<=");
50
        buffer.append(LESS_THAN_OR_EQUAL);
50
        buffer.append( operands[1] );
51
        buffer.append( operands[1] );
51
        return buffer.toString();
52
        return buffer.toString();
52
    }
53
    }
(-)src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java (-1 / +2 lines)
Lines 25-30 Link Here
25
public class UnknownPtg extends Ptg {
25
public class UnknownPtg extends Ptg {
26
    private short size = 1;
26
    private short size = 1;
27
    private final int _sid;
27
    private final int _sid;
28
    private final static String UNKNOWN = "UNKNOWN";
28
29
29
    public UnknownPtg(int sid) {
30
    public UnknownPtg(int sid) {
30
        _sid = sid;
31
        _sid = sid;
Lines 42-48 Link Here
42
    }
43
    }
43
44
44
    public String toFormulaString() {
45
    public String toFormulaString() {
45
        return "UNKNOWN";
46
        return UNKNOWN;
46
    }
47
    }
47
    public byte getDefaultOperandClass() {
48
    public byte getDefaultOperandClass() {
48
        return Ptg.CLASS_VALUE;
49
        return Ptg.CLASS_VALUE;
(-)src/java/org/apache/poi/ss/formula/ptg/DividePtg.java (-1 / +2 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class DividePtg extends ValueOperatorPtg {
25
public final class DividePtg extends ValueOperatorPtg {
26
    public final static byte sid  = 0x06;
26
    public final static byte sid  = 0x06;
27
    private final static String DIVIDE = "/";
27
28
28
    public static final ValueOperatorPtg instance = new DividePtg();
29
    public static final ValueOperatorPtg instance = new DividePtg();
29
30
Lines 43-49 Link Here
43
        StringBuffer buffer = new StringBuffer();
44
        StringBuffer buffer = new StringBuffer();
44
45
45
        buffer.append(operands[ 0 ]);
46
        buffer.append(operands[ 0 ]);
46
        buffer.append("/");
47
        buffer.append(DIVIDE);
47
        buffer.append(operands[ 1 ]);
48
        buffer.append(operands[ 1 ]);
48
        return buffer.toString();
49
        return buffer.toString();
49
    }      
50
    }      
(-)src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java (-1 / +2 lines)
Lines 24-29 Link Here
24
 */
24
 */
25
public final class MultiplyPtg extends ValueOperatorPtg {
25
public final class MultiplyPtg extends ValueOperatorPtg {
26
    public final static byte sid  = 0x05;
26
    public final static byte sid  = 0x05;
27
    private final static String MULT = "*";
27
28
28
    public static final ValueOperatorPtg instance = new MultiplyPtg();
29
    public static final ValueOperatorPtg instance = new MultiplyPtg();
29
30
Lines 43-49 Link Here
43
        StringBuffer buffer = new StringBuffer();
44
        StringBuffer buffer = new StringBuffer();
44
45
45
        buffer.append(operands[ 0 ]);
46
        buffer.append(operands[ 0 ]);
46
        buffer.append("*");
47
        buffer.append(MULT);
47
        buffer.append(operands[ 1 ]);
48
        buffer.append(operands[ 1 ]);
48
        return buffer.toString();
49
        return buffer.toString();
49
    }                  
50
    }                  
(-)src/testcases/org/apache/poi/ss/formula/ptg/TestArea3DPtg.java (-1 / +23 lines)
Lines 19-24 Link Here
19
19
20
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
20
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
import org.apache.poi.ss.SpreadsheetVersion;
23
import org.apache.poi.ss.util.AreaReference;
22
24
23
/**
25
/**
24
 * Tests for Area3DPtg
26
 * Tests for Area3DPtg
Lines 27-38 Link Here
27
 */
29
 */
28
public final class TestArea3DPtg extends AbstractPtgTestCase {
30
public final class TestArea3DPtg extends AbstractPtgTestCase {
29
31
32
	@SuppressWarnings("deprecation")
33
	public void testConstructors() {
34
		final String ref = "A1:B1";
35
		final SpreadsheetVersion version = SpreadsheetVersion.EXCEL97;
36
		final AreaReference areaRef = new AreaReference("A1:B1", version);
37
		
38
		final Area3DPtg aptgRef = new Area3DPtg(0, 0, 0, 1, true, true, true, true, -1);
39
		Area3DPtg aptg;
40
		aptg = new Area3DPtg(areaRef, -1);
41
		assertTrue(aptgRef.equals(aptg));
42
		assertEquals(aptgRef, aptg);
43
		
44
		aptg = new Area3DPtg(ref, -1); //deprecated
45
		assertEquals(aptgRef, aptg);
46
		
47
		aptg = new Area3DPtg(0, 0, 0, 1, true, true, true, true, -1);
48
		assertEquals(aptgRef, aptg);
49
	}
50
	
30
	/**
51
	/**
31
	 * confirms that sheet names get properly escaped
52
	 * confirms that sheet names get properly escaped
32
	 */
53
	 */
33
	public void testToFormulaString() {
54
	public void testToFormulaString() {
34
55
35
		Area3DPtg target = new Area3DPtg("A1:B1", (short)0);
56
		final AreaReference ref = new AreaReference("A1:B1", SpreadsheetVersion.EXCEL97);
57
		Area3DPtg target = new Area3DPtg(ref, (short)0);
36
58
37
		String sheetName = "my sheet";
59
		String sheetName = "my sheet";
38
		HSSFWorkbook wb = createWorkbookWithSheet(sheetName);
60
		HSSFWorkbook wb = createWorkbookWithSheet(sheetName);
(-)src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java (+24 lines)
Lines 22-27 Link Here
22
22
23
import org.apache.poi.hssf.model.HSSFFormulaParser;
23
import org.apache.poi.hssf.model.HSSFFormulaParser;
24
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
24
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
25
import org.apache.poi.ss.SpreadsheetVersion;
26
import org.apache.poi.ss.util.AreaReference;
25
27
26
/**
28
/**
27
 * Tests for {@link AreaPtg}.
29
 * Tests for {@link AreaPtg}.
Lines 41-46 Link Here
41
		relative = new AreaPtg(firstRow,lastRow,firstCol,lastCol,true,true,true,true);
43
		relative = new AreaPtg(firstRow,lastRow,firstCol,lastCol,true,true,true,true);
42
		absolute = new AreaPtg(firstRow,lastRow,firstCol,lastCol,false,false,false,false);
44
		absolute = new AreaPtg(firstRow,lastRow,firstCol,lastCol,false,false,false,false);
43
	}
45
	}
46
	
47
	@SuppressWarnings("deprecation")
48
    public void testConstructors()
49
	{
50
	    final String ref = "A5:B7";
51
	    final SpreadsheetVersion version = SpreadsheetVersion.EXCEL2007;
52
	    
53
        AreaPtg aptg;
54
	    aptg = new AreaPtg(new AreaReference(ref, version));
55
	    assertEquals(ref, aptg.toFormulaString());
56
	    
57
	    // FIXME: add AreaPtg(LittleEndianInput) test
58
	    
59
	    aptg = new AreaPtg(ref); //deprecated
60
	    assertEquals(ref, aptg.toFormulaString());
61
	    
62
	    aptg = new AreaPtg(ref, version);
63
	    assertEquals(ref, aptg.toFormulaString());
64
	    
65
	    aptg = new AreaPtg(4,6,0,1,true,true,true,true);
66
	    assertEquals(ref, aptg.toFormulaString());
67
	}
44
68
45
	public void testSetColumnsAbsolute()
69
	public void testSetColumnsAbsolute()
46
	{
70
	{

Return to bug 58331