Bug 19079

Summary: [PATCH] formula fixes for IF support, conditionals, string handling
Product: POI Reporter: fred
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: avik
Priority: P3    
Version: 2.0-dev   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: diff -u requested, note does not include new files (second try)

Description fred 2003-04-16 16:55:47 UTC
I didn't have any luck with subscribing to or posting messages to the POI
mailing lists, so this is a long post... The following diff and new files
are against the cvs repostiory for POI. The changes included here are:

Change to string handling in a formula to allow for more characters within a
string.  I am not sure """" is being handled correctly.

The argument pointers are set in the method that calls Expression() instead of
in Expression() itself which caused too many arguments to functions for more
complex expressions.

Support for other conditionals besides '='. > and >= have been tested.

Minor changes to operator handling.

I left in the isSpecialCharacter() and getNameAsIs().  I didn't refactor the
record types (a lot of duplicated code there).  Do with this as you wish...

=============================================================================
Diff of model/FormulaParser.java:
=============================================================================

cvs diff model/FormulaParser.java
Index: model/FormulaParser.java
===================================================================
RCS file:
/home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java,v
retrieving revision 1.9
diff -r1.9 FormulaParser.java
72a73,77
> import org.apache.poi.hssf.record.formula.LessPtg;
> import org.apache.poi.hssf.record.formula.GreaterPtg;
> import org.apache.poi.hssf.record.formula.LessEqualPtg;
> import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
> import org.apache.poi.hssf.record.formula.NotEqualPtg;
157c162
<         //System.out.println("Got char: "+Look);
---
>         //System.out.println("Got char: "+look);
416c421
< 
---
> 
429c434
<                
---
> 
434d438
< 
449a454
> 
477a483
>             addArgumentPointer();
486a493
>             addArgumentPointer();
499d505
<             return;
520,522c526,542
<         String name= GetNameAsIs();
<         Match('"');
<         tokens.add(new StringPtg(name));
---
> 
>         StringBuffer Token = new StringBuffer();
>         for(;;) {
>             if(look == '"') {
>                 GetChar();
>                 if(look == '"')
>                     Token.append("\"");
>                 else
>                     break;
>             } else if(look == 0) {
>                 break;
>             } else {
>                 Token.append(look);
>                 GetChar();
>             }
>         }
>         tokens.add(new StringPtg(Token.toString()));
546c566
<         while (look == '*' || look == '/' || look == '^' || look == '&' ||
look == '=' ) {
---
>         while (look == '*' || look == '/' || look == '^' || look == '&') {
549,552c569,571
<             if (look == '/') Divide();
<             if (look == '^') Power();
<             if (look == '&') Concat();
<             if (look == '=') Equal();
---
>             else if (look == '/') Divide();
>             else if (look == '^') Power();
>             else if (look == '&') Concat();
573c592
<         Term();
---
>         Expression();
576c595,635
<     
---
> 
>     private void Greater() {
>         Match('>');
>         if(look == '=')
>             GreaterEqual();
>         else {
>             Expression();
>             tokens.add(new GreaterPtg());
>         }
>     }
> 
>     private void GreaterEqual() {
>         Match('=');
>         Expression();
>         tokens.add(new GreaterEqualPtg());
>     }
> 
>     private void Less() {
>         Match('<');
>         if(look == '=')
>             LessEqual();
>         else if(look == '>')
>             NotEqual();
>         else {
>             Expression();
>             tokens.add(new LessPtg());
>         }
>     }
> 
>     private void LessEqual() {
>         Match('=');
>         Expression();
>         tokens.add(new LessEqualPtg());
>     }
> 
>     private void NotEqual() {
>         Match('>');
>         Expression();
>         tokens.add(new NotEqualPtg());
>     }
> 
600,602c659
<             if (look == '-') Subtract();
<             if (look == '*') Multiply();
<             if (look == '/') Divide();
---
>             else if (look == '-') Subtract();
604,605c661,672
<         addArgumentPointer();
<         
---
> 
> /*
>  * This isn't quite right since it would allow multiple comparison operators.
>  */
> 
>         if(look == '=' || look == '>' || look == '<') {
>             if (look == '=') Equal();
>             else if (look == '>') Greater();
>             else if (look == '<') Less();
>             return;
>         }
> 

=============================================================================
Diff of record/formula/Ptg.java:
=============================================================================
cvs diff record/formula/Ptg.java
Index: record/formula/Ptg.java
===================================================================
RCS file:
/home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Ptg.java,v
retrieving revision 1.25
diff -r1.25 Ptg.java
178a179,198
> 
>             case LessPtg.sid:
>                 retval = new LessPtg(data, offset);
>                 break;
>                 
>             case GreaterPtg.sid:
>                 retval = new GreaterPtg(data, offset);
>                 break;
>                 
>             case LessEqualPtg.sid:
>                 retval = new LessEqualPtg(data, offset);
>                 break;
>                 
>             case GreaterEqualPtg.sid:
>                 retval = new GreaterEqualPtg(data, offset);
>                 break;
> 
>             case NotEqualPtg.sid:
>                 retval = new NotEqualPtg(data, offset);
>                 break;

===========================
New file record/formula/GreaterEqualPtg.java:
===========================
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache POI" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    "Apache POI", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * LessPtg.java
 *
 * Created on November 17, 2001, 12:51 PM
 */
package org.apache.poi.hssf.record.formula;

import java.util.List;

import org.apache.poi.hssf.util.SheetReferences;

/**
 *
 * @author  andy
 */

public class GreaterEqualPtg
    extends OperationPtg
{
    public final static int  SIZE = 1;
    public final static byte sid  = 0x0c;

    /** Creates new AddPtg */

   public GreaterEqualPtg()
    {
    }

    public GreaterEqualPtg(byte [] data, int offset)
    {

        // doesn't need anything
    }

    public void writeBytes(byte [] array, int offset)
    {
        array[ offset + 0 ] = sid;
    }

    public int getSize()
    {
        return SIZE;
    }

    public int getType()
    {
        return TYPE_BINARY;
    }

    public int getNumberOfOperands()
    {
        return 2;
    }

    public String toFormulaString(SheetReferences refs)
    {
        return ">=";
    }
 
    public String toFormulaString(String[] operands) {
         StringBuffer buffer = new StringBuffer();

        
        buffer.append(operands[ 0 ]);
        buffer.append(toFormulaString((SheetReferences)null));
        buffer.append(operands[ 1 ]);
        return buffer.toString();
    }       

    public Object clone() {
      return new GreaterEqualPtg();
    }


}

====================================
New file record/formula/GreaterPtg.java:
====================================

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache POI" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    "Apache POI", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * LessPtg.java
 *
 * Created on November 17, 2001, 12:51 PM
 */
package org.apache.poi.hssf.record.formula;

import java.util.List;

import org.apache.poi.hssf.util.SheetReferences;

/**
 *
 * @author  andy
 */

public class GreaterPtg
    extends OperationPtg
{
    public final static int  SIZE = 1;
    public final static byte sid  = 0x0d;

    /** Creates new AddPtg */

   public GreaterPtg()
    {
    }

    public GreaterPtg(byte [] data, int offset)
    {

        // doesn't need anything
    }

    public void writeBytes(byte [] array, int offset)
    {
        array[ offset + 0 ] = sid;
    }

    public int getSize()
    {
        return SIZE;
    }

    public int getType()
    {
        return TYPE_BINARY;
    }

    public int getNumberOfOperands()
    {
        return 2;
    }

    public String toFormulaString(SheetReferences refs)
    {
        return ">";
    }
 
    public String toFormulaString(String[] operands) {
         StringBuffer buffer = new StringBuffer();

        
        buffer.append(operands[ 0 ]);
        buffer.append(toFormulaString((SheetReferences)null));
        buffer.append(operands[ 1 ]);
        return buffer.toString();
    }       

    public Object clone() {
      return new GreaterPtg();
    }


}

=============================
New file record/formula/LessEqualPtg.java:
=============================

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache POI" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    "Apache POI", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * LessPtg.java
 *
 * Created on November 17, 2001, 12:51 PM
 */
package org.apache.poi.hssf.record.formula;

import java.util.List;

import org.apache.poi.hssf.util.SheetReferences;

/**
 *
 * @author  andy
 */

public class LessEqualPtg
    extends OperationPtg
{
    public final static int  SIZE = 1;
    public final static byte sid  = 0x0a;

    /** Creates new AddPtg */

   public LessEqualPtg()
    {
    }

    public LessEqualPtg(byte [] data, int offset)
    {

        // doesn't need anything
    }

    public void writeBytes(byte [] array, int offset)
    {
        array[ offset + 0 ] = sid;
    }

    public int getSize()
    {
        return SIZE;
    }

    public int getType()
    {
        return TYPE_BINARY;
    }

    public int getNumberOfOperands()
    {
        return 2;
    }

    public String toFormulaString(SheetReferences refs)
    {
        return "<=";
    }
 
    public String toFormulaString(String[] operands) {
         StringBuffer buffer = new StringBuffer();

        
        buffer.append(operands[ 0 ]);
        buffer.append(toFormulaString((SheetReferences)null));
        buffer.append(operands[ 1 ]);
        return buffer.toString();
    }       

    public Object clone() {
      return new LessEqualPtg();
    }


}

==================================
New file record/formula/LessPtg.java:
==================================

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache POI" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    "Apache POI", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * LessPtg.java
 *
 * Created on November 17, 2001, 12:51 PM
 */
package org.apache.poi.hssf.record.formula;

import java.util.List;

import org.apache.poi.hssf.util.SheetReferences;

/**
 *
 * @author  andy
 */

public class LessPtg
    extends OperationPtg
{
    public final static int  SIZE = 1;
    public final static byte sid  = 0x09;

    /** Creates new AddPtg */

   public LessPtg()
    {
    }

    public LessPtg(byte [] data, int offset)
    {

        // doesn't need anything
    }

    public void writeBytes(byte [] array, int offset)
    {
        array[ offset + 0 ] = sid;
    }

    public int getSize()
    {
        return SIZE;
    }

    public int getType()
    {
        return TYPE_BINARY;
    }

    public int getNumberOfOperands()
    {
        return 2;
    }

    public String toFormulaString(SheetReferences refs)
    {
        return "<";
    }
 
    public String toFormulaString(String[] operands) {
         StringBuffer buffer = new StringBuffer();

        
        buffer.append(operands[ 0 ]);
        buffer.append(toFormulaString((SheetReferences)null));
        buffer.append(operands[ 1 ]);
        return buffer.toString();
    }       

    public Object clone() {
      return new LessPtg();
    }


}

===============================
New file record/formula/NotEqualPtg.java:
===============================
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache POI" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    "Apache POI", nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * NotPtg.java
 *
 * Created on November 17, 2001, 12:51 PM
 */
package org.apache.poi.hssf.record.formula;

import java.util.List;

import org.apache.poi.hssf.util.SheetReferences;

/**
 *
 * @author  andy
 */

public class NotEqualPtg
    extends OperationPtg
{
    public final static int  SIZE = 1;
    public final static byte sid  = 0x0e;

    /** Creates new AddPtg */

   public NotEqualPtg()
    {
    }

    public NotEqualPtg(byte [] data, int offset)
    {

        // doesn't need anything
    }

    public void writeBytes(byte [] array, int offset)
    {
        array[ offset + 0 ] = sid;
    }

    public int getSize()
    {
        return SIZE;
    }

    public int getType()
    {
        return TYPE_BINARY;
    }

    public int getNumberOfOperands()
    {
        return 2;
    }

    public String toFormulaString(SheetReferences refs)
    {
        return "<>";
    }
 
    public String toFormulaString(String[] operands) {
         StringBuffer buffer = new StringBuffer();

        
        buffer.append(operands[ 0 ]);
        buffer.append(toFormulaString((SheetReferences)null));
        buffer.append(operands[ 1 ]);
        return buffer.toString();
    }       

    public Object clone() {
      return new NotEqualPtg();
    }


}
Comment 1 Danny Mui 2003-04-16 17:03:17 UTC
oooh, thanks for taking care of this ugly work.  can you click "Create a new
attachment" to attach files from now on?

can you use 'cvs diff -u' for creating a patch?

we would also love for you to create testcases.  we have a conditionals patch
that's only missing testcases as a reason for not being committed.  we need to
make sure any new formulaparser changes do not break the fixes you provided.

Comment 2 fred 2003-04-16 17:27:47 UTC
I can't tell from this if the diff -u attachment was sucessful.  If not I will
try again.  The diff -u does not appear to include the new files.  Also
test cases is a little more difficult.  I have a wrapper that generates a
spreadsheet from a database query, but does things like get the cell types
correct and supports formulas.  My test cases are currently in XML and run
through a converter that translates R1C1 format to cell names and generates
a conditional. So I can't really just give you the 6 or so test cases that
I already have.  I will look into generating a couple though.

Comment 3 fred 2003-04-16 17:47:10 UTC
Created attachment 5868 [details]
diff -u requested, note does not include new files (second try)
Comment 4 Danny Mui 2003-04-16 18:45:51 UTC
the unified patch looks good...usually you have to tar/zip up the new files.

testcases are pretty simple for formulas..typically we usually check if the ptgs
are generated as expected.  TestFormulaParser has a lot of examples.  If you
have 6 testcases, i'm assuming that's 6 different formulas you're testing. 
worst case scenario, 6 new methods to write ;).

thanks!

Comment 5 Avik Sengupta 2003-05-05 19:26:35 UTC
Danny, are you going to commit this? Given that this did not have patch in its
title, i missed it while doing the other bug. I can do this tomorrow for sure ,
unless you beat me to it. Given my previous commit, which surely clash with this
one, it seems that, again, this patch will have to be applied line by line!! 
Comment 6 Danny Mui 2003-05-05 19:47:07 UTC
Yeah I've been feeling naughty and will commit this.  I'll do the line by line
and add test cases.  I was going to remove the greater/less than stuff since we
already had a patch for that.
Comment 7 Danny Mui 2003-05-07 03:57:47 UTC
Committed with 2 test methods that test the new ptgs inside an embedded.  Thanks
for the contribution