if ( ValueType.NUMBER == valueType && !MathUtils.isNumeric( value ) ) else if ( ValueType.UNIT_INTERVAL == valueType && !MathUtils.isUnitInterval( value ) ) else if ( ValueType.PERCENTAGE == valueType && !MathUtils.isPercentage( value ) ) else if ( ValueType.INTEGER == valueType && !MathUtils.isInteger( value ) ) else if ( ValueType.INTEGER_POSITIVE == valueType && !MathUtils.isPositiveInteger( value ) ) else if ( ValueType.INTEGER_NEGATIVE == valueType && !MathUtils.isNegativeInteger( value ) ) else if ( ValueType.INTEGER_ZERO_OR_POSITIVE == valueType && !MathUtils.isZeroOrPositiveInteger( value ) ) else if ( ValueType.BOOLEAN == valueType && !MathUtils.isBool( value ) ) else if ( ValueType.COORDINATE == valueType && !MathUtils.isCoordinate( value ) )
/** * Tests whether the given double is equal to zero. * * @param value the value. * @return true or false. */ public static boolean isZero( double value ) { return isEqual( value, 0d ); }
/** * Evaluates whether an expression is true or false. * * @param leftSide The left side of the expression. * @param operator The expression operator. * @param rightSide The right side of the expression. * @return True if the expression is true, false otherwise. */ public static boolean expressionIsTrue( double leftSide, Operator operator, double rightSide ) { final String expression = leftSide + operator.getMathematicalOperator() + rightSide; return expressionIsTrue( expression ); }
/** * Rounds the fractional part of a number to a given number of significant * decimal digits. Digits to the left of the decimal point will not * be rounded. For example, rounding 12345 to 3 digits will be 12345, * whereas 12.345 will be 12.3, and 0.12345 will be 0.123. * * @param value the value to round off. * @param n the number of significant fraction decimal digits desired. * @return a rounded off number. */ public static double roundFraction( double value, int n ) { if ( isEqual( value, 0.0 ) ) { return 0.0; } final double d = Math.ceil( Math.log10( value < 0.0 ? -value : value ) ); if ( d >= n ) { return (double) Math.round( value ); } return roundToSignificantDigits( value ,n ); }
/** * Evaluates whether an expression is true or false. * * @param expression the expression to evaluate. * @return True if the expression is true, false otherwise. */ public static boolean expressionIsTrue( String expression ) { final JEP parser = getJep(); parser.parseExpression( expression ); return isEqual( parser.getValue(), 1.0 ); }
/** * Returns true if the provided string argument is to be considered a unit * interval, which implies that the value is numeric and inclusive between 0 * and 1. * * @param value the value. * @return true if the provided string argument is to be considered a unit interval. */ public static boolean isUnitInterval( String value ) { if ( !isNumeric( value ) ) { return false; } Double dbl = Double.parseDouble( value ); return dbl >= 0d && dbl <= 1d; }
else if ( !MathUtils.isZero( target) ) // REPORTING_RATE or REPORTING_RATE_ON_TIME .addValue( params.isSkipRounding() ? value : MathUtils.getRounded( value ) );
/** * Returns a rounded off number. If the value class is not Double, the value * is returned unchanged. * * @param value the value to return and potentially round off. */ public static Object getRoundedObject( Object value ) { return value != null && Double.class.equals( value.getClass() ) ? getRounded( (Double) value ) : value; }
final double denominatorValue = calculateExpression( denominatorExpression ); if ( !isEqual( denominatorValue, 0d ) ) final double numeratorValue = calculateExpression( numeratorExpression );
/** * Indicates whether the given value is zero and not zero significant according * to its data element. * * @param value the data value. * @param dataElement the data element. */ public static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement ) { AggregationType aggregationType = dataElement.getAggregationType(); return dataElement.getValueType().isNumeric() && MathUtils.isZero( value ) && !dataElement.isZeroIsSignificant() && !( aggregationType == AggregationType.AVERAGE_SUM_ORG_UNIT || aggregationType == AggregationType.AVERAGE ); }
@Override public Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, ListMap<String, Double> aggregateMap ) { String expressionString = generateExpression( expression.getExpression(), valueMap, constantMap, orgUnitCountMap, days, expression.getMissingValueStrategy(), aggregateMap ); return expressionString != null ? calculateExpression( expressionString ) : null; }
/** * Retrieves the measure criteria from the given string. Criteria are separated * by the option separator, while the criterion filter and value are separated * with the dimension name separator. */ public static Map<MeasureFilter, Double> getMeasureCriteriaFromParam( String param ) { if ( param == null ) { return null; } Map<MeasureFilter, Double> map = new HashMap<>(); String[] criteria = param.split( DimensionalObject.OPTION_SEP ); for ( String c : criteria ) { String[] criterion = c.split( DimensionalObject.DIMENSION_NAME_SEP ); if ( criterion != null && criterion.length == 2 && MathUtils.isNumeric( criterion[1] ) ) { MeasureFilter filter = MeasureFilter.valueOf( criterion[0] ); Double value = Double.valueOf( criterion[1] ); map.put( filter, value ); } } return map; }
/** * Rounds a value. If the given parameters has skip rounding, the value is * returned unchanged. If the given number is null or not of class Double, * the value is returned unchanged. If skip rounding is specified in the * given data query parameters, 10 decimals is used. Otherwise, default * rounding is used. * * @param params the query parameters. * @param value the value. * @return a value. */ public static Object getRoundedValueObject( DataQueryParams params, Object value ) { if ( value == null || !Double.class.equals( value.getClass() ) ) { return value; } else if ( params.isSkipRounding() ) { return Precision.round( (Double) value, DECIMALS_NO_ROUNDING ); } return MathUtils.getRounded( (Double) value ); }
/** * Evaluates the skip test expression for any sample periods in which * skip test data occurs. For any combination of period and attribute * option combo where the skip test is true, removes all sample data with * that combination of period and attribute option combo. * * @param dataMap all data values (both skip and aggregate). * @param skipTest the skip test expression. * @param constantMap constants to use in skip expression if needed. */ private void applySkipTest( MapMapMap<Period, String, DimensionalItemObject, Double> dataMap, Expression skipTest, Map<String, Double> constantMap ) { if ( skipTest != null && dataMap != null ) { for ( Period period : dataMap.keySet() ) { MapMap<String, DimensionalItemObject, Double> periodData = dataMap.get( period ); for ( String aoc : periodData.keySet() ) { Double testValue = expressionService.getExpressionValue( skipTest, periodData.get( aoc ), constantMap, null, period.getDaysInPeriod() ); if ( testValue != null && !MathUtils.isZero( testValue ) ) { periodData.remove( aoc ); } } } } }
if ( column != null && MathUtils.isNumeric( String.valueOf( column ) ) )
/** * Rounds a number to a given number of significant decimal digits. * Note that the number will be left with *only* this number of * significant digits regardless of magnitude, e.g. 12345 to 3 digits * will be 12300, whereas 0.12345 will be 0.123. * * @param value the value to round off. * @param n the number of significant decimal digits desired. * @return a rounded off number. */ public static double roundToSignificantDigits( double value, int n ) { if ( isEqual( value, 0.0 ) ) { return 0.0; } final double d = Math.ceil( Math.log10( value < 0.0 ? -value : value ) ); final int power = n - (int) d; final double magnitude = Math.pow( 10.0, power ); final long shifted = Math.round( value * magnitude ); return shifted / magnitude; }
/** * Fill grid with aggregated data map with key and value * * @param params the {@link DataQueryParams}. * @param grid the grid * @param aggregatedDataMap the aggregated data map */ private void fillGridWithAggregatedDataMap( DataQueryParams params, Grid grid, Map<String, Double> aggregatedDataMap) { for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() ) { Double value = params.isSkipRounding() ? entry.getValue() : MathUtils.getRounded( entry.getValue() ); grid.addRow() .addValues( entry.getKey().split( DIMENSION_SEP ) ) .addValue( value ); if ( params.isIncludeNumDen() ) { grid.addNullValues( 3 ); } } }
return !expressionIsTrue( leftSide, ruleX.getRule().getOperator(), rightSide );