Java源码示例:org.pentaho.reporting.libraries.formula.LibFormulaErrorValue

示例1
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final Number result = context.getTypeRegistry().convertToNumber( type1, value1 );
  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }
  final double d = StrictMath.log( result.doubleValue() );

  final BigDecimal divide =
    new BigDecimal( d ).divide( LOG10BASE, LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_HALF_UP );
  return new TypeValuePair( NumberType.GENERIC_NUMBER, NumberUtil.removeTrailingZeros( divide ) );
}
 
示例2
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int length = parameters.getParameterCount();
  if ( length != 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final TypeRegistry typeRegistry = context.getTypeRegistry();
  final Object value1Raw = parameters.getValue( 0 );
  final Object value2Raw = parameters.getValue( 1 );
  if ( value1Raw == null || value2Raw == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_NA_VALUE );
  }

  final Type type1 = parameters.getType( 0 );
  final Type type2 = parameters.getType( 1 );
  final ExtendedComparator comparator = typeRegistry.getComparator( type1, type2 );
  final boolean result = comparator.isEqual( type1, value1Raw, type2, value2Raw );
  if ( result ) {
    return RETURN_TRUE;
  } else {
    return RETURN_FALSE;
  }

}
 
示例3
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );


  try {
    return new TypeValuePair( NumberType.GENERIC_NUMBER, context.getTypeRegistry().convertToNumber( type1, value1 ) );
  } catch ( EvaluationException e ) {
    return ZERO;
  }
}
 
示例4
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  if ( parameters.getParameterCount() != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final TypeRegistry typeRegistry = context.getTypeRegistry();
  final Date d = typeRegistry.convertToDate( parameters.getType( 0 ), parameters.getValue( 0 ) );

  if ( d == null ) {
    throw EvaluationException.getInstance(
      LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  final Calendar gc = DateUtil.createCalendar( d, context.getLocalizationContext() );

  final int month = gc.get( Calendar.MONTH ) + 1;
  return new TypeValuePair( NumberType.GENERIC_NUMBER, new BigDecimal( month ) );
}
 
示例5
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount > 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final ReportFormulaContext rfc = (ReportFormulaContext) context;
  final int groupStart;
  if ( parameterCount == 0 ) {
    groupStart = rfc.getRuntime().getGroupStartRow( -1 );
  } else {
    final String groupName =
        context.getTypeRegistry().convertToText( parameters.getType( 0 ), parameters.getValue( 0 ) );
    groupStart = rfc.getRuntime().getGroupStartRow( groupName );
  }
  final int row = rfc.getRuntime().getCurrentRow();
  // noinspection UnpredictableBigDecimalConstructorCall
  return new TypeValuePair( NumberType.GENERIC_NUMBER, new BigDecimal( (double) ( row - groupStart ) ) );
}
 
示例6
public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final Number result = context.getTypeRegistry().convertToNumber( type1, value1 );
  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }
  final double d = result.doubleValue();
  if ( d < 1.0 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }
  return new TypeValuePair( NumberType.GENERIC_NUMBER, new BigDecimal( Math.log( d + Math.sqrt( d * d - 1.0 ) ) ) );
}
 
示例7
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 2 ) {
    throw new EvaluationException( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final Type textType1 = parameters.getType( 0 );
  final Object textValue1 = parameters.getValue( 0 );
  final Type textType2 = parameters.getType( 1 );
  final Object textValue2 = parameters.getValue( 1 );

  final String text = typeRegistry.convertToText( textType1, textValue1 );
  final String substring = typeRegistry.convertToText( textType2, textValue2 );

  return text.contains( substring ) ? RETURN_TRUE : RETURN_FALSE;
}
 
示例8
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  if ( parameters.getParameterCount() != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final Number result = context.getTypeRegistry().convertToNumber( type1, value1 );
  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  final Number ret = NumberUtil.performIntRounding( NumberUtil.getAsBigDecimal( result ) );
  return new TypeValuePair( NumberType.GENERIC_NUMBER, ret );
}
 
示例9
public final TypeValuePair evaluate( final FormulaContext context,
                                     final TypeValuePair value1,
                                     final TypeValuePair value2 )
  throws EvaluationException {
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  if ( value1 == null || value2 == null ) {
    // If this happens, then one of the implementations has messed up.
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE );
  }

  final Object raw1 = value1.getValue();
  final Object raw2 = value2.getValue();
  if ( raw1 == null || raw2 == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_NA_VALUE );
  }

  final Number number1 = convertToNumber( typeRegistry, value1.getType(), raw1, ZERO );
  final Number number2 = convertToNumber( typeRegistry, value2.getType(), raw2, ZERO );
  return new TypeValuePair( NumberType.GENERIC_NUMBER, evaluate( number1, number2 ) );
}
 
示例10
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 2 ) {
    throw new EvaluationException( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final Type textType1 = parameters.getType( 0 );
  final Object textValue1 = parameters.getValue( 0 );
  final Type textType2 = parameters.getType( 1 );
  final Object textValue2 = parameters.getValue( 1 );

  final String text = typeRegistry.convertToText( textType1, textValue1 );

  String regex = typeRegistry.convertToText( textType2, textValue2 );

  // replace any * or % with .*
  regex = regex.replaceAll( "\\*", ".*" ).replaceAll( "%", ".*" );

  Pattern p = Pattern.compile( regex );
  Matcher m = p.matcher( text );

  return m.find() ? RETURN_TRUE : RETURN_FALSE;
}
 
示例11
private TypeValuePair get( final int pos ) throws EvaluationException {
  final LValue parameter = function.parameters[ pos ];
  final Type paramType = function.metaData.getParameterType( pos );
  if ( parameter != null ) {
    final TypeValuePair result = parameter.evaluate();
    if ( result.getValue() == null ) {
      return result;
    }

    // lets do some type checking, right?
    final TypeRegistry typeRegistry = function.getContext().getTypeRegistry();
    final TypeValuePair converted = typeRegistry.convertTo( paramType, result );
    if ( converted == null ) {
      if ( logger.isDebugEnabled() ) {
        logger.debug( "Failed to evaluate parameter " + pos + " on function " + function );
      }
      throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_AUTO_ARGUMENT_VALUE );
    }
    return converted;
  } else {
    return new TypeValuePair( paramType, function.metaData.getDefaultValue( pos ) );
  }
}
 
示例12
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int length = parameters.getParameterCount();
  if ( length < 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final TypeRegistry typeRegistry = context.getTypeRegistry();
  final Object value1Raw = parameters.getValue( 0 );
  final Type type1 = parameters.getType( 0 );
  for ( int i = 1; i < parameters.getParameterCount(); i++ ) {
    final Object value2Raw = parameters.getValue( i );
    if ( value1Raw == null || value2Raw == null ) {
      throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_NA_VALUE );
    }

    final Type type2 = parameters.getType( i );
    final ExtendedComparator comparator = typeRegistry.getComparator( type1, type2 );
    final boolean result = comparator.isEqual( type1, value1Raw, type2, value2Raw );
    if ( result ) {
      return RETURN_TRUE;
    }
  }
  return RETURN_FALSE;
}
 
示例13
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();

  if ( parameterCount == 0 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  int count = 0;

  for ( int paramIdx = 0; paramIdx < parameterCount; paramIdx++ ) {
    try {
      final Object value = parameters.getValue( paramIdx );
      final Sequence sequence = new RecursiveSequence( value, context );
      while ( sequence.hasNext() ) {
        final Object o = sequence.next();
        count += countElement( o );
      }
    } catch ( EvaluationException e ) {
      count++;
    }
  }

  return new TypeValuePair( NumberType.GENERIC_NUMBER, new BigDecimal( count ) );
}
 
示例14
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 2 ) {
    throw new EvaluationException( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final Type textType1 = parameters.getType( 0 );
  final Object textValue1 = parameters.getValue( 0 );
  final Type textType2 = parameters.getType( 1 );
  final Object textValue2 = parameters.getValue( 1 );

  final String text = typeRegistry.convertToText( textType1, textValue1 );
  final String substring = typeRegistry.convertToText( textType2, textValue2 );

  return text.startsWith( substring ) ? RETURN_TRUE : RETURN_FALSE;
}
 
示例15
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters )
  throws EvaluationException {
  if ( parameters.getParameterCount() < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final int length = parameters.getParameterCount();
  for ( int i = 0; i < length; i++ ) {
    final Type conditionType = parameters.getType( i );
    final Object conditionValue = parameters.getValue( i );
    final Boolean condition = context.getTypeRegistry().convertToLogical( conditionType, conditionValue );
    if ( condition == null ) {
      throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
    }
    if ( Boolean.TRUE.equals( condition ) ) {
      return RETURN_TRUE;
    }
  }
  return RETURN_FALSE;

}
 
示例16
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  if ( parameters.getParameterCount() == 0 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  if ( parameters.getParameterCount() > 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final Type textType = parameters.getType( 0 );
  final Object textValueRaw = parameters.getValue( 0 );
  final String text = context.getTypeRegistry().convertToText( textType, textValueRaw );

  Number code = null;
  if ( parameters.getParameterCount() == 2 ) {
    final Type codeType = parameters.getType( 1 );
    final Object codeRaw = parameters.getValue( 1 );
    code = context.getTypeRegistry().convertToNumber( codeType, codeRaw );
  }
  if ( code == null ) {
    code = -1;
  }
  throw EvaluationException.getInstance( new CustomErrorValue( code.intValue(), text ) );
}
 
示例17
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException
{
  final int parameterCount = parameters.getParameterCount();
  if (parameterCount < 1)
  {
    throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
  }

  final Object value = parameters.getValue(0);
  if(value instanceof Number)
  {
    return RETURN_TRUE;
  }

  return RETURN_FALSE;
}
 
示例18
/**
 * Return Boolean.TRUE, if the specified export type matches the used export type, Boolean.FALSE otherwise.
 *
 * @param context
 *          the formula context, which allows access to the runtime.
 * @param parameters
 *          the parameter callback is used to retrieve parameter values.
 * @return the computed result wrapped in a TypeValuePair.
 * @throws EvaluationException
 *           if an error occurs.
 */
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  if ( context instanceof ReportFormulaContext == false ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE );
  }
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final Object value = parameters.getValue( 0 );
  final ReportFormulaContext rfc = (ReportFormulaContext) context;
  if ( value != null && rfc.getExportType().startsWith( String.valueOf( value ) ) ) {
    return new TypeValuePair( LogicalType.TYPE, Boolean.TRUE );
  }

  return new TypeValuePair( LogicalType.TYPE, Boolean.FALSE );
}
 
示例19
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final Type textType1 = parameters.getType( 0 );
  final Object textValue1 = parameters.getValue( 0 );
  final Type textType2 = parameters.getType( 1 );
  final Object textValue2 = parameters.getValue( 1 );

  final String text = typeRegistry.convertToText( textType1, textValue1 );
  final String substring = typeRegistry.convertToText( textType2, textValue2 );

  return text.contains( substring ) ? RETURN_TRUE : RETURN_FALSE;
}
 
示例20
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final Type textType1 = parameters.getType( 0 );
  final Object textValue1 = parameters.getValue( 0 );
  final Type textType2 = parameters.getType( 1 );
  final Object textValue2 = parameters.getValue( 1 );

  final String text = typeRegistry.convertToText( textType1, textValue1 );
  final String substring = typeRegistry.convertToText( textType2, textValue2 );

  return text.startsWith( substring ) ? RETURN_TRUE : RETURN_FALSE;
}
 
示例21
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters )
  throws EvaluationException {
  if ( parameters.getParameterCount() != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type conditionType = parameters.getType( 0 );
  final Object conditionValue = parameters.getValue( 0 );
  final Boolean condition = context.getTypeRegistry().convertToLogical( conditionType, conditionValue );
  if ( condition == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }
  if ( !Boolean.TRUE.equals( condition ) ) {
    return RETURN_TRUE;
  }
  return RETURN_FALSE;
}
 
示例22
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters )
  throws EvaluationException {
  final int length = parameters.getParameterCount();
  if ( length < 2 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }

  final TypeRegistry typeRegistry = context.getTypeRegistry();
  final Object value1Raw = parameters.getValue( 0 );
  final Type type1 = parameters.getType( 0 );
  for ( int i = 1; i < parameters.getParameterCount(); i++ ) {
    final Object value2Raw = parameters.getValue( i );
    if ( value1Raw == null || value2Raw == null ) {
      throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_NA_VALUE );
    }

    final Type type2 = parameters.getType( i );
    final ExtendedComparator comparator = typeRegistry.getComparator( type1, type2 );
    final boolean result = comparator.isEqual( type1, value1Raw, type2, value2Raw );
    if ( result ) {
      return RETURN_TRUE;
    }
  }
  return RETURN_FALSE;
}
 
示例23
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final String result = context.getTypeRegistry().convertToText( type1, value1 );

  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  return new TypeValuePair( NumberType.GENERIC_NUMBER, new BigDecimal( result.length() ) );
}
 
示例24
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final String message = context.getTypeRegistry().convertToText( type1, value1 );

  final MessageFormat format = new MessageFormat( message, context.getLocalizationContext().getLocale() );
  final Object[] args = new Object[ parameterCount - 1 ];
  for ( int i = 1; i < parameterCount; i += 1 ) {
    args[ i - 1 ] = parameters.getValue( i );
  }
  return new TypeValuePair( TextType.TYPE, format.format( args ) );
}
 
示例25
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final String result = context.getTypeRegistry().convertToText( type1, value1 );

  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  return new TypeValuePair( TextType.TYPE, capitalize( result ) );
}
 
示例26
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final String result = context.getTypeRegistry().convertToText( type1, value1 );

  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  return new TypeValuePair( TextType.TYPE, result.toUpperCase( context.getLocalizationContext().getLocale() ) );
}
 
示例27
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount < 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final Number result = context.getTypeRegistry().convertToNumber( type1, value1 );

  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  return new TypeValuePair( TextType.TYPE, String.valueOf( ( (char) result.intValue() ) ) );
}
 
示例28
public TypeValuePair evaluate( final FormulaContext context,
                               final ParameterCallback parameters ) throws EvaluationException {
  final int parameterCount = parameters.getParameterCount();
  if ( parameterCount != 1 ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE );
  }
  final Type type1 = parameters.getType( 0 );
  final Object value1 = parameters.getValue( 0 );
  final TypeRegistry typeRegistry = context.getTypeRegistry();

  final String result = typeRegistry.convertToText( type1, value1 );
  if ( result == null ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE );
  }

  final char[] chars = result.toCharArray();
  final StringBuffer b = new StringBuffer( chars.length );
  for ( int i = 0; i < chars.length; i++ ) {
    final char c = chars[ i ];
    convert( c, b );
  }
  return new TypeValuePair( TextType.TYPE, b.toString() );
}
 
示例29
public Object[][] createDataTest() {
  return new Object[][]
    {
      { "IF(FALSE();7;8)", new BigDecimal( 8 ) },
      { "IF(TRUE();7;8)", new BigDecimal( 7 ) },
      { "IF(TRUE();\"HI\";8)", "HI" },
      { "IF(1;7;8)", new BigDecimal( 7 ) },
      { "IF(5;7;8)", new BigDecimal( 7 ) },
      { "IF(0;7;8)", new BigDecimal( 8 ) },
      { "IF(TRUE();[.B4];8)", new BigDecimal( 2 ) },
      { "IF(TRUE();[.B4]+5;8)", new BigDecimal( 7 ) },
      { "IF(\"x\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE },
      { "IF(\"1\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE },
      { "IF(\"\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE },
      { "IF(FALSE();7)", Boolean.FALSE },
      { "IF(FALSE();7;)", Boolean.FALSE },
      { "IF(FALSE();;7)", new BigDecimal( 7 ) },
      //TODO { "IF(FALSE();7;)", new BigDecimal(0) }, we will not allow this syntax
      { "IF(TRUE();4;1/0)", new BigDecimal( 4 ) },
      { "IF(FALSE();1/0;5)", new BigDecimal( 5 ) },
    };
}
 
示例30
private TypeValuePair get( final int row, final int column )
  throws EvaluationException {
  if ( row < 0 || row >= rowCount ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE );
  }
  if ( column < 0 || column >= columnCount ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE );
  }
  try {
    TypeValuePair value = backend[ row ][ column ];
    if ( value == null ) {
      value = getRaw( row, column ).evaluate();
      backend[ row ][ column ] = value;
    }
    return value;
  } catch ( IndexOutOfBoundsException ioe ) {
    throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE );
  }
}