Java Code Examples for org.eclipse.birt.core.data.DataTypeUtil#toDouble()
The following examples show how to use
org.eclipse.birt.core.data.DataTypeUtil#toDouble() .
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: TotalRunningNpv.java From birt with Eclipse Public License 1.0 | 6 votes |
public void onRow( Object[] args ) throws DataException { assert ( args.length > 0 ); if ( args[0] != null ) { try { if ( count == 1 ) { if ( args[1] != null ) rate = DataTypeUtil.toDouble( args[1] ) .doubleValue( ); else rate = DataTypeUtil.toDouble( 0 ); } npv = calculator.add( npv, calculator.divide( calculator.getTypedObject( args[0] ), calculator.getTypedObject( Math.pow( ( 1 + rate ), (double) count++ ) ) ) ); } catch ( BirtException e ) { throw DataException.wrap( new AggrException( ResourceConstants.DATATYPEUTIL_ERROR, e ) ); } } }
Example 2
Source File: TotalNpv.java From birt with Eclipse Public License 1.0 | 6 votes |
public void onRow( Object[] args ) throws DataException { assert ( args.length > 0 ); if ( args[0] != null ) { try { if ( count == 1 ) { if ( args[1] != null ) rate = DataTypeUtil.toDouble( args[1] ) .doubleValue( ); else rate = DataTypeUtil.toDouble( 0 ); } npv = calculator.add( npv, calculator.divide( calculator.getTypedObject( args[0] ), calculator.getTypedObject( Math.pow( ( 1 + rate ), (double) count++ ) ) ) ); } catch ( BirtException e ) { throw DataException.wrap( new AggrException( ResourceConstants.DATATYPEUTIL_ERROR, e ) ); } } }
Example 3
Source File: TemplateMessageServiceBaseImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
private Object convertValue(String type, String value) throws BirtException { if (DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals(type)) { return DataTypeUtil.toBoolean(value); } else if (DesignChoiceConstants.PARAM_TYPE_DATETIME.equals(type)) { return DataTypeUtil.toDate(value); } else if (DesignChoiceConstants.PARAM_TYPE_DATE.equals(type)) { return DataTypeUtil.toSqlDate(value); } else if (DesignChoiceConstants.PARAM_TYPE_TIME.equals(type)) { return DataTypeUtil.toSqlTime(value); } else if (DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals(type)) { return DataTypeUtil.toBigDecimal(value); } else if (DesignChoiceConstants.PARAM_TYPE_FLOAT.equals(type)) { return DataTypeUtil.toDouble(value); } else if (DesignChoiceConstants.PARAM_TYPE_STRING.equals(type)) { return DataTypeUtil.toLocaleNeutralString(value); } else if (DesignChoiceConstants.PARAM_TYPE_INTEGER.equals(type)) { return DataTypeUtil.toInteger(value); } return value; }
Example 4
Source File: ReportRunner.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param p * the scalar parameter * @param expr * the default value expression */ protected Object stringToObject( int type, String value ) throws BirtException { if ( value == null ) { return null; } switch ( type ) { case IScalarParameterDefn.TYPE_BOOLEAN : return DataTypeUtil.toBoolean( value ); case IScalarParameterDefn.TYPE_DATE : return DataTypeUtil.toSqlDate( value ); case IScalarParameterDefn.TYPE_TIME : return DataTypeUtil.toSqlTime( value ); case IScalarParameterDefn.TYPE_DATE_TIME : return DataTypeUtil.toDate( value ); case IScalarParameterDefn.TYPE_DECIMAL : return DataTypeUtil.toBigDecimal( value ); case IScalarParameterDefn.TYPE_FLOAT : return DataTypeUtil.toDouble( value ); case IScalarParameterDefn.TYPE_STRING : return DataTypeUtil.toString( value ); case IScalarParameterDefn.TYPE_INTEGER : return DataTypeUtil.toInteger( value ); } return null; }
Example 5
Source File: MathUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * add operation. * * @param obj1 * @param obj2 * @return * @throws BirtException */ public static final Number toNumber( Object obj1 ) throws BirtException { if ( obj1 == null ) { return null; } if ( obj1 instanceof BigDecimal ) { return (BigDecimal) obj1; } return DataTypeUtil.toDouble( obj1 ); }
Example 6
Source File: MathUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param number * @return * @throws BirtException */ public static final Number negate( Object number ) throws BirtException { assert ( number != null ); if ( number instanceof BigDecimal ) { return ( (BigDecimal) number ).negate( ); } else { return DataTypeUtil.toDouble( number ) * ( -1 ); } }
Example 7
Source File: MathUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param number * @return * @throws BirtException */ public static final int compare( Object number1, Object number2 ) throws BirtException { assert ( number1 != null && number2 != null ); if ( number1 instanceof BigDecimal ) { if ( number2 instanceof BigDecimal ) { return ( (BigDecimal) number1 ).compareTo( (BigDecimal) number2 ); } else { return ( (BigDecimal) number1 ).compareTo( new BigDecimal( DataTypeUtil.toDouble( number2 ) ) ); } } else { Double d1 = DataTypeUtil.toDouble( number1 ); if ( number2 instanceof BigDecimal ) { return ( new BigDecimal( DataTypeUtil.toDouble( d1 ) ) ).compareTo( (BigDecimal) number2 ); } else { return d1.compareTo( DataTypeUtil.toDouble( number2 ) ); } } }
Example 8
Source File: DataUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Try convert an object to given type Types supported: * <p> * <ul> * <li>IScalarParameterDefn.TYPE_INTEGER</li> * <li>IScalarParameterDefn.TYPE_DECIMAL</li> * <li>IScalarParameterDefn.TYPE_BOOLEAN</li> * <li>IScalarParameterDefn.TYPE_DATE_TIME</li> * <li>IScalarParameterDefn.TYPE_FLOAT</li> * <li>IScalarParameterDefn.TYPE_STRING</li> * <li>IScalarParameterDefn.TYPE_DATE</li> * <li>IScalarParameterDefn.TYPE_TIME</li> * <ul> * </p> * * @param source * @param toType * @return * @throws BirtException */ public static Object convert( Object source, int toType ) throws BirtException { if ( source == null ) return null; // if any type, return directly. if ( toType == IScalarParameterDefn.TYPE_ANY ) return source; switch ( toType ) { case IScalarParameterDefn.TYPE_INTEGER : return DataTypeUtil.toInteger( source ); case IScalarParameterDefn.TYPE_DECIMAL : return DataTypeUtil.toBigDecimal( source ); case IScalarParameterDefn.TYPE_BOOLEAN : return DataTypeUtil.toBoolean( source ); case IScalarParameterDefn.TYPE_DATE_TIME : return DataTypeUtil.toDate( source ); case IScalarParameterDefn.TYPE_FLOAT : return DataTypeUtil.toDouble( source ); case IScalarParameterDefn.TYPE_STRING : return DataTypeUtil.toString( source ); case IScalarParameterDefn.TYPE_DATE : return DataTypeUtil.toSqlDate( source ); case IScalarParameterDefn.TYPE_TIME : return DataTypeUtil.toSqlTime( source ); default : throw new CoreException( "Invalid type." ); //$NON-NLS-1$ } }
Example 9
Source File: ParameterUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
public static Object convert( Object value, String dataType ) throws BirtException { if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( dataType ) ) { return DataTypeUtil.toBoolean( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( dataType ) ) { return DataTypeUtil.toDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( dataType ) ) { return DataTypeUtil.toSqlDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( dataType ) ) { return DataTypeUtil.toSqlTime( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( dataType ) ) { return DataTypeUtil.toBigDecimal( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( dataType ) ) { return DataTypeUtil.toDouble( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( dataType ) ) { return DataTypeUtil.toString( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( dataType ) ) { return DataTypeUtil.toInteger( value ); } return value; }
Example 10
Source File: DataTypeConvertUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
public static Object convert( Object value, String type ) throws BirtException { if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( type ) ) { return DataTypeUtil.toBoolean( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( type ) ) { return DataTypeUtil.toDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( type ) ) { return DataTypeUtil.toBigDecimal( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( type ) ) { return DataTypeUtil.toDouble( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( type ) ) { return DataTypeUtil.toString( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( type ) ) { return DataTypeUtil.toInteger( value ); } return value; }
Example 11
Source File: EngineTask.java From birt with Eclipse Public License 1.0 | 5 votes |
public static Object convertParameterType( Object value, String type ) throws BirtException { if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( type ) ) { return DataTypeUtil.toBoolean( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( type ) ) { return DataTypeUtil.toDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( type ) ) { return DataTypeUtil.toSqlDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( type ) ) { return DataTypeUtil.toSqlTime( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( type ) ) { return DataTypeUtil.toBigDecimal( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( type ) ) { return DataTypeUtil.toDouble( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( type ) ) { return DataTypeUtil.toLocaleNeutralString( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( type ) ) { return DataTypeUtil.toInteger( value ); } return value; }
Example 12
Source File: ParameterSelectionChoice.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * set parameter choice value. The string value is in English locale, and needs to be parsed * back into object value based on the data type. * * @param value the string value for the object * @param type the parameter data type */ public void setValue(String value, int type) { try { switch (type) { case IScalarParameterDefn.TYPE_BOOLEAN: this.value = DataTypeUtil.toBoolean(value); break; case IScalarParameterDefn.TYPE_DATE_TIME: this.value = DataTypeUtil.toDate(value); break; case IScalarParameterDefn.TYPE_DECIMAL: this.value = DataTypeUtil.toBigDecimal(value); break; case IScalarParameterDefn.TYPE_FLOAT: this.value = DataTypeUtil.toDouble(value); break; case IScalarParameterDefn.TYPE_INTEGER: this.value = DataTypeUtil.toInteger( value ); break; case IScalarParameterDefn.TYPE_DATE: this.value = DataTypeUtil.toSqlDate( value ); break; case IScalarParameterDefn.TYPE_TIME: this.value = DataTypeUtil.toSqlTime( value ); break; case IScalarParameterDefn.TYPE_STRING: default: this.value = DataTypeUtil.toString(value); break; } } catch (BirtException e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); this.value = null; } }
Example 13
Source File: NumberCalculator.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object getTypedObject( Object obj ) throws DataException { try { return DataTypeUtil.toDouble( obj ); } catch ( BirtException e ) { throw DataException.wrap( e ); } }
Example 14
Source File: ReportLauncher.java From birt with Eclipse Public License 1.0 | 4 votes |
public static Object convert( Object value, String dataType ) throws BirtException { if (value == null) { return value; } if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( dataType ) ) { return DataTypeUtil.toBoolean( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( dataType ) ) { return DataTypeUtil.toDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( dataType ) ) { return DataTypeUtil.toSqlDate( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( dataType ) ) { return DataTypeUtil.toSqlTime( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( dataType ) ) { return DataTypeUtil.toBigDecimal( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( dataType ) ) { return DataTypeUtil.toDouble( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( dataType ) ) { return DataTypeUtil.toString( value ); } else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( dataType ) ) { return DataTypeUtil.toInteger( value ); } return value; }
Example 15
Source File: ResultIterator.java From birt with Eclipse Public License 1.0 | 4 votes |
public Double getDouble( String name ) throws BirtException { return DataTypeUtil.toDouble( getValue( name ) ); }
Example 16
Source File: CacheResultIterator.java From birt with Eclipse Public License 1.0 | 4 votes |
public Double getDouble( String name ) throws BirtException { return DataTypeUtil.toDouble( getValue( name ) ); }
Example 17
Source File: ResultIterator.java From birt with Eclipse Public License 1.0 | 4 votes |
public Double getDouble( String name ) throws BirtException { return DataTypeUtil.toDouble( getValue( name ) ); }
Example 18
Source File: PreparedDummyQuery.java From birt with Eclipse Public License 1.0 | 4 votes |
public Double getDouble( String name ) throws BirtException { return DataTypeUtil.toDouble( this.getValue( name ) ); }
Example 19
Source File: BaseScriptEvalUtil.java From birt with Eclipse Public License 1.0 | 4 votes |
private static Object[] populateObArray( Object obj, Object[] obArray ) { try { for ( int i = 0; i < obArray.length; i++ ) { if( obArray[i] instanceof Object[] ) return obArray; } if ( obj instanceof Number && !( obj instanceof BigDecimal ) ) { for ( int i = 0; i < obArray.length; i++ ) { obArray[i] = DataTypeUtil.toDouble( obArray[i] ); } } else if ( obj instanceof java.sql.Date ) { for ( int i = 0; i < obArray.length; i++ ) { obArray[i] = DataTypeUtil.toSqlDate( obArray[i] ); } } else if ( obj instanceof java.sql.Time ) { for ( int i = 0; i < obArray.length; i++ ) { obArray[i] = DataTypeUtil.toSqlTime( obArray[i] ); } } else if ( obj instanceof Date ) { for ( int i = 0; i < obArray.length; i++ ) { obArray[i] = DataTypeUtil.toDate( obArray[i] ); } } } catch ( BirtException e ) { // If failed to convert to same date type for comparation, // simply convert them to String. try { makeObjectArrayStringArray( obArray ); } catch ( BirtException e1 ) { //should never reach here. } } // obArray will remain the same if obj is String rather than // Date,Number or Boolean return obArray; }
Example 20
Source File: Finance.java From birt with Eclipse Public License 1.0 | 4 votes |
private static double getDouble( Object o ) throws BirtException { if( o == null ) return Double.NaN; return DataTypeUtil.toDouble( o ); }