poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Svede <jsv...@yahoo.com>
Subject UDF Feature question
Date Wed, 06 Oct 2010 04:16:40 GMT
I was able to set up my own UDF but I noticed something that I can't explain 
clearly, I am hoping someone can help me.  This is again related to documenting 
this feature.

In my FreeRefFunction implementation class, for the array of ValueEval objects, 
I get a mix of things.  In some cases I get an instance of NumberEval but in 
others I've gotten a LazyRefEval.  This confused me for a minute, then I 
realized I could cast it to RefEval, call the getInnerType() method which could 
then be cast to the NumberEval.

This seems a little confusing, am I doing this right?  Or is there a better 
way?  Here is the code that I wrote:

  @Override
  public ValueEval evaluate( ValueEval[] args, OperationEvaluationContext ec ) {
    if (args.length != 2 ) {
      return ErrorEval.VALUE_INVALID;
    }
  
    NumberEval numEval1 = getNumberEval( args[0] );
    NumberEval numEval2 = getNumberEval(args[1]) ;
    
    double var1 = numEval1.getNumberValue() ;
    double var2 = numEval2.getNumberValue() ;

    double result = calculateH2_ZFactor( var1, var2 ) ; 
    
    return new NumberEval( result ) ;
  }
  
  /**
   * In order to deal with my functions I need two numbers and they 
   * get passed differently depending on where they are called from.  This
   * function encapsulates the steps needed to convert the input to the
   * NumberEval object. (this may not even be right)
   * 
   * @param vEval
   * @return
   */
  private NumberEval getNumberEval( ValueEval vEval ) {
    if( vEval != null ) {
      if( vEval instanceof RefEval ) {
        RefEval rEval = (RefEval)vEval ;
        return( NumberEval)rEval.getInnerValueEval() ;
        
      } else if( vEval instanceof NumberEval ) {
        return (NumberEval)vEval ;
      }
    }
    
    return null ;
  }

It's the getNumberEval() method where all this casting happens and I think that 
has to be wrong.

If it's not wrong, is there an explanation I can provide?

Another question is, I assume that the implementation of the evaluate() method 
does not throw any exceptions, rather the values from ErrorEval should be used 
to express a problem?

Thanks,

Jon


      

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


Mime
View raw message