Standardised toString methods on ScalarConstantPtg subclasses

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@684067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-08-08 19:49:02 +00:00
parent ad4abd484a
commit cb842b1165
7 changed files with 49 additions and 79 deletions

View File

@ -17,7 +17,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -30,36 +29,30 @@ import org.apache.poi.hssf.record.RecordInputStream;
public final class BoolPtg extends ScalarConstantPtg {
public final static int SIZE = 2;
public final static byte sid = 0x1d;
private final boolean field_1_value;
private final boolean _value;
public BoolPtg(RecordInputStream in)
{
field_1_value = (in.readByte() == 1);
public BoolPtg(RecordInputStream in) {
_value = (in.readByte() == 1);
}
public BoolPtg(String formulaToken) {
field_1_value = (formulaToken.equals("TRUE"));
_value = (formulaToken.equalsIgnoreCase("TRUE"));
}
public boolean getValue()
{
return field_1_value;
public boolean getValue() {
return _value;
}
public void writeBytes(byte [] array, int offset)
{
public void writeBytes(byte [] array, int offset) {
array[ offset + 0 ] = sid;
array[ offset + 1 ] = (byte) (field_1_value ? 1 : 0);
array[ offset + 1 ] = (byte) (_value ? 1 : 0);
}
public int getSize()
{
public int getSize() {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
{
return field_1_value ? "TRUE" : "FALSE";
protected String toFormulaString() {
return _value ? "TRUE" : "FALSE";
}
}

View File

@ -17,7 +17,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
@ -68,7 +67,7 @@ public final class ErrPtg extends ScalarConstantPtg {
array[offset + 1] = (byte)field_1_error_code;
}
public String toFormulaString(HSSFWorkbook book) {
protected String toFormulaString() {
return HSSFErrorConstants.getText(field_1_error_code);
}

View File

@ -17,9 +17,8 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndian;
/**
* Integer (unsigned short integer)
@ -60,8 +59,7 @@ public final class IntPtg extends ScalarConstantPtg {
return field_1_value;
}
public void writeBytes(byte [] array, int offset)
{
public void writeBytes(byte [] array, int offset) {
array[ offset + 0 ] = sid;
LittleEndian.putUShort(array, offset + 1, getValue());
}
@ -70,15 +68,7 @@ public final class IntPtg extends ScalarConstantPtg {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book) {
protected String toFormulaString() {
return String.valueOf(getValue());
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(field_1_value);
sb.append("]");
return sb.toString();
}
}

View File

@ -17,8 +17,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* Missing Function Arguments
*
@ -31,22 +29,20 @@ public final class MissingArgPtg extends ScalarConstantPtg {
public final static byte sid = 0x16;
public static final Ptg instance = new MissingArgPtg();
private MissingArgPtg()
{
private MissingArgPtg() {
// enforce singleton
}
public void writeBytes(byte [] array, int offset)
{
public void writeBytes(byte [] array, int offset) {
array[ offset + 0 ] = sid;
}
public int getSize()
{
public int getSize() {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
{
protected String toFormulaString() {
return " ";
}
}

View File

@ -17,9 +17,8 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndian;
/**
* Number
@ -34,8 +33,7 @@ public final class NumberPtg extends ScalarConstantPtg {
private final double field_1_value;
/** Create a NumberPtg from a byte array read from disk */
public NumberPtg(RecordInputStream in)
{
public NumberPtg(RecordInputStream in) {
this(in.readDouble());
}
@ -52,33 +50,21 @@ public final class NumberPtg extends ScalarConstantPtg {
field_1_value = value;
}
public double getValue()
{
public double getValue() {
return field_1_value;
}
public void writeBytes(byte [] array, int offset)
{
public void writeBytes(byte [] array, int offset) {
array[ offset + 0 ] = sid;
LittleEndian.putDouble(array, offset + 1, getValue());
}
public int getSize()
{
public int getSize() {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
{
protected String toFormulaString() {
// TODO - java's rendering of double values is not quite same as excel's
return String.valueOf(field_1_value);
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(field_1_value);
sb.append("]");
return sb.toString();
}
}

View File

@ -17,6 +17,8 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* @author Josh Micich
*/
@ -24,7 +26,22 @@ abstract class ScalarConstantPtg extends Ptg {
public boolean isBaseToken() {
return true;
}
public final byte getDefaultOperandClass() {
return Ptg.CLASS_VALUE;
}
public final byte getDefaultOperandClass() {
return Ptg.CLASS_VALUE;
}
public final String toFormulaString(HSSFWorkbook book) {
return toFormulaString();
}
protected abstract String toFormulaString();
public final String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(toFormulaString());
sb.append("]");
return sb.toString();
}
}

View File

@ -17,11 +17,10 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil;
import org.apache.poi.hssf.record.RecordInputStream;
/**
* String Stores a String value in a formula value stored in the format
@ -55,8 +54,6 @@ public final class StringPtg extends ScalarConstantPtg {
} else {
field_3_string = in.readCompressedUnicode(field_1_length);
}
// setValue(new String(data, offset+3, data[offset+1] + 256*data[offset+2]));
}
/**
@ -100,7 +97,7 @@ public final class StringPtg extends ScalarConstantPtg {
}
}
public String toFormulaString(HSSFWorkbook book) {
protected String toFormulaString() {
String value = field_3_string;
int len = value.length();
StringBuffer sb = new StringBuffer(len + 4);
@ -117,12 +114,4 @@ public final class StringPtg extends ScalarConstantPtg {
sb.append(FORMULA_DELIMITER);
return sb.toString();
}
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
sb.append(field_3_string);
sb.append("]");
return sb.toString();
}
}