From 931b516a02b906a10c5f53ce2c13fecff7252678 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Sat, 5 Dec 2009 01:04:44 +0000 Subject: [PATCH] Controlled instantiation of BoolPtg (made consistent with ErrPtg) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@887477 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/BoolPtg.java | 21 ++++++++++++------- .../apache/poi/hssf/record/formula/Ptg.java | 2 +- .../apache/poi/ss/formula/FormulaParser.java | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java b/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java index 88604ac50d..ecac699020 100644 --- a/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java @@ -22,22 +22,29 @@ import org.apache.poi.util.LittleEndianOutput; /** * Boolean (boolean) Stores a (java) boolean value in a formula. - * + * * @author Paul Krause (pkrause at soundbite dot com) * @author Andrew C. Oliver (acoliver at apache dot org) * @author Jason Height (jheight at chariot dot net dot au) */ public final class BoolPtg extends ScalarConstantPtg { - public final static int SIZE = 2; - public final static byte sid = 0x1D; + public static final int SIZE = 2; + public static final byte sid = 0x1D; + + private static final BoolPtg FALSE = new BoolPtg(false); + private static final BoolPtg TRUE = new BoolPtg(true); + private final boolean _value; - public BoolPtg(LittleEndianInput in) { - _value = (in.readByte() == 1); + private BoolPtg(boolean b) { + _value = b; } - public BoolPtg(String formulaToken) { - _value = (formulaToken.equalsIgnoreCase("TRUE")); + public static BoolPtg valueOf(boolean b) { + return b ? TRUE : FALSE; + } + public static BoolPtg read(LittleEndianInput in) { + return valueOf(in.readByte() == 1); } public boolean getValue() { diff --git a/src/java/org/apache/poi/hssf/record/formula/Ptg.java b/src/java/org/apache/poi/hssf/record/formula/Ptg.java index 2426249c15..dba30f322a 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Ptg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Ptg.java @@ -152,7 +152,7 @@ public abstract class Ptg { case StringPtg.sid: return new StringPtg(in); // 0x17 case AttrPtg.sid: return new AttrPtg(in); // 0x19 case ErrPtg.sid: return ErrPtg.read(in); // 0x1c - case BoolPtg.sid: return new BoolPtg(in); // 0x1d + case BoolPtg.sid: return BoolPtg.read(in); // 0x1d case IntPtg.sid: return new IntPtg(in); // 0x1e case NumberPtg.sid: return new NumberPtg(in); // 0x1f } diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java index 46d7fbfee1..a750ed13f2 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java @@ -551,7 +551,7 @@ public final class FormulaParser { return function(name); } if (name.equalsIgnoreCase("TRUE") || name.equalsIgnoreCase("FALSE")) { - return new ParseNode(new BoolPtg(name.toUpperCase())); + return new ParseNode(BoolPtg.valueOf(name.equalsIgnoreCase("TRUE"))); } if (_book == null) { // Only test cases omit the book (expecting it not to be needed) -- 2.39.5