poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r684067 - in /poi/trunk/src/java/org/apache/poi/hssf/record/formula: BoolPtg.java ErrPtg.java IntPtg.java MissingArgPtg.java NumberPtg.java ScalarConstantPtg.java StringPtg.java
Date Fri, 08 Aug 2008 19:49:03 GMT
Author: josh
Date: Fri Aug  8 12:49:02 2008
New Revision: 684067

URL: http://svn.apache.org/viewvc?rev=684067&view=rev
Log:
Standardised toString methods on ScalarConstantPtg subclasses

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java Fri Aug  8 12:49:02
2008
@@ -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 @@
 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";
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java Fri Aug  8 12:49:02
2008
@@ -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 @@
         array[offset + 1] = (byte)field_1_error_code;
     }
 
-    public String toFormulaString(HSSFWorkbook book) {
+    protected String toFormulaString() {
         return HSSFErrorConstants.getText(field_1_error_code);
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java Fri Aug  8 12:49:02
2008
@@ -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 @@
         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 @@
         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();
-    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java Fri Aug  8 12:49:02
2008
@@ -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 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 " ";
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java Fri Aug  8 12:49:02
2008
@@ -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 @@
     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 @@
         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();
-    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java Fri Aug 
8 12:49:02 2008
@@ -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 @@
 	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();
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java?rev=684067&r1=684066&r2=684067&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java Fri Aug  8 12:49:02
2008
@@ -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 @@
         } 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 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 @@
         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();
-    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message