org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType Java Examples

The following examples show how to use org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IsExportTypeFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 );
}
 
Example #2
Source File: DollarFunctionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ParameterCallback getMockedParameterCallback( Object... parameterValues ) throws EvaluationException {
  ParameterCallback parameter = mock( ParameterCallback.class );
  when( parameter.getParameterCount() ).thenReturn( parameterValues.length );
  int i = 0;
  for ( Object parameterValue : parameterValues ) {
    Type parameterType = AnyType.TYPE;
    if ( parameterValue instanceof BigDecimal ) {
      parameterType = NumberType.GENERIC_NUMBER;
    } else if ( parameterValue instanceof Boolean ) {
      parameterType = LogicalType.TYPE;
    } else if ( parameterValue instanceof String ) {
      parameterType = TextType.TYPE;
    }
    when( parameter.getType( eq( i ) ) ).thenReturn( NumberType.GENERIC_NUMBER );
    when( parameter.getValue( eq( i ) ) ).thenReturn( parameterValue );
    ++i;
  }

  return parameter;
}
 
Example #3
Source File: FixedFunctionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ParameterCallback getMockedParameterCallback( Object... parameterValues ) throws EvaluationException {
  ParameterCallback parameter = mock( ParameterCallback.class );
  when( parameter.getParameterCount() ).thenReturn( parameterValues.length );
  int i = 0;
  for ( Object parameterValue : parameterValues ) {
    Type parameterType = AnyType.TYPE;
    if ( parameterValue instanceof BigDecimal ) {
      parameterType = NumberType.GENERIC_NUMBER;
    } else if ( parameterValue instanceof Boolean ) {
      parameterType = LogicalType.TYPE;
    } else if ( parameterValue instanceof String ) {
      parameterType = TextType.TYPE;
    }
    when( parameter.getType( eq( i ) ) ).thenReturn( parameterType );
    when( parameter.getValue( eq( i ) ) ).thenReturn( parameterValue );
    ++i;
  }

  return parameter;
}
 
Example #4
Source File: AcoshFunctionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ParameterCallback getMockedParameterCallback( Object... parameterValues ) throws EvaluationException {
  ParameterCallback parameter = mock( ParameterCallback.class );
  when( parameter.getParameterCount() ).thenReturn( parameterValues.length );
  int i = 0;
  for ( Object parameterValue : parameterValues ) {
    Type parameterType = AnyType.TYPE;
    if ( parameterValue instanceof BigDecimal ) {
      parameterType = NumberType.GENERIC_NUMBER;
    } else if ( parameterValue instanceof Boolean ) {
      parameterType = LogicalType.TYPE;
    } else if ( parameterValue instanceof String ) {
      parameterType = TextType.TYPE;
    }
    when( parameter.getType( eq( i ) ) ).thenReturn( NumberType.GENERIC_NUMBER );
    when( parameter.getValue( eq( i ) ) ).thenReturn( parameterValue );
    ++i;
  }

  return parameter;
}
 
Example #5
Source File: DefaultTypeRegistry.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Type guessTypeOfObject( final Object o ) {
  if ( o instanceof Number ) {
    return NumberType.GENERIC_NUMBER;
  } else if ( o instanceof Time ) {
    return DateTimeType.TIME_TYPE;
  } else if ( o instanceof java.sql.Date ) {
    return DateTimeType.DATE_TYPE;
  } else if ( o instanceof Date ) {
    return DateTimeType.DATETIME_TYPE;
  } else if ( o instanceof Boolean ) {
    return LogicalType.TYPE;
  } else if ( o instanceof String ) {
    return TextType.TYPE;
  }

  return AnyType.TYPE;
}
 
Example #6
Source File: CsvArrayFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the parameter type at the given position using the function metadata. The first parameter is at the
 * position 0;
 *
 * @param position The parameter index.
 * @return The parameter type.
 */
public Type getParameterType( final int position ) {
  if ( position == 1 ) {
    return LogicalType.TYPE;
  }

  return TextType.TYPE;
}
 
Example #7
Source File: MParameterTextFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the parameter type of the function parameters.
 *
 * @param position
 *          the parameter index.
 * @return always TextType.TYPE.
 */
public Type getParameterType( final int position ) {
  if ( position == 2 ) {
    return LogicalType.TYPE;
  }
  if ( position == 1 || position == 3 ) {
    return TextType.TYPE;
  }
  return AnyType.TYPE;
}
 
Example #8
Source File: ParameterTextFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the parameter type of the function parameters.
 *
 * @param position
 *          the parameter index.
 * @return always TextType.TYPE.
 */
public Type getParameterType( final int position ) {
  if ( position == 1 ) {
    return LogicalType.TYPE;
  }
  if ( position == 2 ) {
    return TextType.TYPE;
  }
  return AnyType.TYPE;
}
 
Example #9
Source File: EngineeringNotationFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the parameter type at the given position using the function metadata. The first parameter is at the
 * position 0;
 *
 * @param position
 *          The parameter index.
 * @return The parameter type.
 */
public Type getParameterType( final int position ) {
  switch ( position ) {
    case 0:
      return NumberType.GENERIC_NUMBER;

    case 1:
      return NumberType.GENERIC_NUMBER;

    case 2:
      return LogicalType.TYPE;
  }

  return TextType.TYPE;
}
 
Example #10
Source File: IsEmptyDataFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final ReportFormulaContext rfc = (ReportFormulaContext) context;
  final boolean value = rfc.isResultSetEmpty();

  if ( value ) {
    return new TypeValuePair( LogicalType.TYPE, Boolean.TRUE );
  }

  return new TypeValuePair( LogicalType.TYPE, Boolean.FALSE );
}
 
Example #11
Source File: DashboardModeFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters )
  throws EvaluationException {
  final ReportFormulaContext rfc = (ReportFormulaContext) context;
  if ( isDashboardMode( rfc ) ) {
    return new TypeValuePair( LogicalType.TYPE, Boolean.TRUE );
  }
  return new TypeValuePair( LogicalType.TYPE, Boolean.FALSE );
}
 
Example #12
Source File: IfFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Type getParameterType( final int position ) {
  if ( position == 0 ) {
    return LogicalType.TYPE;
  } else {
    return AnyType.TYPE;
  }
}
 
Example #13
Source File: CsvTextFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the parameter type at the given position using the function metadata. The first parameter is at the
 * position 0;
 *
 * @param position The parameter index.
 * @return The parameter type.
 */
public Type getParameterType( final int position ) {
  if ( position == 0 ) {
    return AnyType.ANY_ARRAY;
  }
  if ( position == 1 ) {
    return LogicalType.TYPE;
  }

  return TextType.TYPE;
}
 
Example #14
Source File: IsBlankFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #15
Source File: IsRefFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #16
Source File: AndFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getParameterType( final int position ) {
  return LogicalType.TYPE;
}
 
Example #17
Source File: AndFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #18
Source File: HasChangedFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #19
Source File: IsEvenFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #20
Source File: IsErrFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #21
Source File: IsTextFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #22
Source File: IsOddFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #23
Source File: IsNumberFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #24
Source File: TrueFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #25
Source File: IsNonTextFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #26
Source File: ArrayContainsFunctionDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #27
Source File: InFunctionDescription.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #28
Source File: ContainsFunctionDescription.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #29
Source File: BeginsWithFunctionDescription.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}
 
Example #30
Source File: EqualsFunctionDescription.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Type getValueType() {
  return LogicalType.TYPE;
}