Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

In this page you can find the example usage for java.lang Double isInfinite.

Prototype

public boolean isInfinite() 

Source Link

Document

Returns true if this Double value is infinitely large in magnitude, false otherwise.

Usage

From source file:org.cloudgraph.hbase.results.ResultsAggregator.java

private void aggregate(FunctionPath funcPath, PlasmaDataGraph existing, PlasmaDataGraph graph) {
    DataType scalarType = funcPath.getFunc().getName().getScalarDatatype(funcPath.getDataType());

    PlasmaDataObject existingEndpoint = null;
    PlasmaDataObject newEndpoint = null;
    if (funcPath.getPath().size() == 0) {
        existingEndpoint = (PlasmaDataObject) existing.getRootObject();
        newEndpoint = (PlasmaDataObject) graph.getRootObject();
    } else {//from ww  w .java  2s.  c o m
        existingEndpoint = (PlasmaDataObject) existing.getRootObject()
                .getDataObject(funcPath.getPath().toString());
        newEndpoint = (PlasmaDataObject) graph.getRootObject().getDataObject(funcPath.getPath().toString());
    }

    Number existingFuncValue = (Number) existingEndpoint.get(funcPath.getFunc().getName(),
            funcPath.getProperty());
    if (funcPath.getFunc().getName().ordinal() == FunctionName.COUNT.ordinal()) {
        Long newCount = existingFuncValue.longValue() + 1;
        if (newCount > 0) {
            existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newCount);
        } else { // overflow
            log.warn("aggregate " + funcPath.getFunc().getName() + " overflow for target type " + scalarType
                    + " - truncating aggregate");
        }
    } else {
        if (newEndpoint.isSet(funcPath.getProperty())) {
            Object newValue = newEndpoint.get(funcPath.getProperty());
            Number newScalarValue = (Number) DataConverter.INSTANCE.convert(scalarType,
                    funcPath.getProperty().getType(), newValue);
            switch (funcPath.getFunc().getName()) {
            case AVG: // Note; computing a sum until all values accumulated
                switch (scalarType) {
                case Double:
                    Double avg = existingFuncValue != null
                            ? existingFuncValue.doubleValue() + newScalarValue.doubleValue()
                            : newScalarValue.doubleValue();
                    existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), avg);
                    break;
                case Float:
                    Float floatAvg = existingFuncValue != null
                            ? existingFuncValue.floatValue() + newScalarValue.floatValue()
                            : newScalarValue.floatValue();
                    existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), floatAvg);
                    break;
                default:
                    throw new IllegalArgumentException("illsgal datatype (" + scalarType
                            + ") conversion for function, " + funcPath.getFunc().getName());
                }
                break;
            case MAX:

                if (existingFuncValue == null || Double.valueOf(newScalarValue.doubleValue())
                        .compareTo(existingFuncValue.doubleValue()) > 0)
                    existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newScalarValue);
                break;
            case MIN:
                if (existingFuncValue == null || Double.valueOf(newScalarValue.doubleValue())
                        .compareTo(existingFuncValue.doubleValue()) < 0)
                    existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newScalarValue);
                break;
            case SUM:
                switch (scalarType) {
                case Double:
                    Double doubleSum = existingFuncValue != null
                            ? existingFuncValue.doubleValue() + newScalarValue.doubleValue()
                            : newScalarValue.doubleValue();
                    if (!doubleSum.isInfinite()) {
                        existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), doubleSum);
                    } else { // overflow
                        log.warn("aggregate " + funcPath.getFunc().getName() + " overflow for target type "
                                + scalarType + " - truncating aggregate");
                    }
                    break;
                case Long:
                    Long longSum = existingFuncValue != null
                            ? existingFuncValue.longValue() + newScalarValue.longValue()
                            : newScalarValue.longValue();
                    if (longSum > 0) {
                        existingEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), longSum);
                    } else { // overflow
                        log.warn("aggregate " + funcPath.getFunc().getName() + " overflow for target type "
                                + scalarType + " - truncating aggregate");
                    }
                    break;
                default:
                    throw new IllegalArgumentException("illegal datatype (" + scalarType
                            + ") conversion for function, " + funcPath.getFunc().getName());
                }
                break;
            default:
                throw new GraphServiceException(
                        "unimplemented aggregate function, " + funcPath.getFunc().getName());
            }
        } else if (!funcPath.getProperty().isNullable())
            log.warn("expected value for non-nullable property, " + funcPath.getProperty());
    }

}

From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java

@SuppressWarnings("nls")
private XYDataset getScatterPlotData(SimpleFeatureCollection features) {
    // "LMiIndex", "LMiZScore", "LMiPValue", "COType"
    XYSeries xySeries = new XYSeries(features.getSchema().getTypeName());
    minMaxVisitor.reset();//from  w w w  .  java2  s.  co  m

    String typeName = features.getSchema().getTypeName();
    SimpleFeatureIterator featureIter = features.features();
    try {
        int i = 0;
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            Coordinate coordinate = geometry.getCentroid().getCoordinate();

            // The X axis of the scatter plot represents the standardised Z values of your
            // variable (that is, theyve been standardised to their Z scores, with a mean of
            // zero, and a standard deviation of 1.)
            Double x = Converters.convert(feature.getAttribute("LMiZScore"), Double.class);
            if (x == null || x.isInfinite() || x.isNaN()) {
                continue;
            }

            // The Y axis represents the standardised values of the neighbouring values around
            // your point of interest, that is the lagged values. These are calculated according
            // to the spatial weights matrix that you specify. So, for instance, if you specify
            // a contiguous spatial weights matrix, with a first order queen contiguity, the
            // value of the y axis represents the mean value of the variable for all of the
            // areas that share a border with the area of interest.
            SpatialEvent source = new SpatialEvent(typeName + "." + ++i, coordinate);
            int neighbors = 0;
            double zSum = 0d;
            for (int j = 0; j < swMatrix.getEvents().size(); j++) {
                SpatialEvent target = swMatrix.getEvents().get(j);
                if (source.id == target.id) {
                    continue;
                }

                double wij = swMatrix.getWeight(source, target);
                if (wij > 0) {
                    neighbors++;
                    zSum += zScore[j];
                }
            }

            double y = neighbors == 0 ? 0d : zSum / neighbors;
            minMaxVisitor.visit(x, y);
            xySeries.add(new XYDataItem2(feature, x, y));
        }
    } finally {
        featureIter.close();
    }

    return new XYSeriesCollection(xySeries);
}

From source file:org.egov.pgr.service.dashboard.DashboardService.java

private List<Map<String, Object>> performanceAnalysis(final List<Object[]> wardwisePerformanceData,
        final DateTime currentDate) {
    final List<Map<String, Object>> compAggrData = new ArrayList<Map<String, Object>>();
    final String formattedFrm = endOfGivenDate(currentDate.minusDays(14)).toString(DFLT_DATE_FRMTR);
    final String formattedDayAfterFrm = startOfGivenDate(currentDate.minusDays(13)).toString(DFLT_DATE_FRMTR);
    final String formattedTo = currentDate.toString(DFLT_DATE_FRMTR);
    final DecimalFormat df = new DecimalFormat("####0.00");
    for (final Object[] compData : wardwisePerformanceData) {
        final Map<String, Object> complaintData = new HashMap<String, Object>();
        complaintData.put("zone", compData[0]);
        final BigInteger compData1 = (BigInteger) compData[1];
        final BigInteger compData3 = (BigInteger) compData[3];
        final BigInteger compData4 = (BigInteger) compData[4];
        final double noOfCompAsOnDate = compData1.doubleValue();
        final double noOfCompReceivedBtw = compData3.doubleValue();
        final double noOfCompPenAsonDate = compData4.doubleValue();
        complaintData.put("dateAsOn2WeekBack", formattedFrm);
        complaintData.put("noOfCompAsOnDate", noOfCompAsOnDate);
        complaintData.put("dateAsOnDayAfter", formattedDayAfterFrm);
        complaintData.put("noOfCompReceivedBtw", noOfCompReceivedBtw);
        complaintData.put("dateAsOn", formattedTo);
        complaintData.put("noOfCompPenAsonDate", noOfCompPenAsonDate);
        final Double disposalPerc = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (disposalPerc.isNaN() || disposalPerc.isInfinite())
            complaintData.put("disposalPerc", "0.00");
        else/*from  w w  w .j a  v  a  2s .  co m*/
            complaintData.put("disposalPerc", df.format(disposalPerc));
        complaintData.put("lat", compData[6]);
        complaintData.put("lng", compData[7]);
        complaintData.put("zoneId", compData[8]);
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "disposalPerc");
    Collections.reverse(compAggrData);
    // ASSIGN A RANK BASED ON ORDER
    assignRank(compAggrData, "rank");
    return compAggrData;
}

From source file:org.displaytag.util.NumberUtils.java

/**
 * <p>Turns a string value into a java.lang.Number.</p>
 *
 * <p>First, the value is examined for a type qualifier on the end
 * (<code>'f','F','d','D','l','L'</code>).  If it is found, it starts 
 * trying to create successively larger types from the type specified
 * until one is found that can represent the value.</p>
 *
 * <p>If a type specifier is not found, it will check for a decimal point
 * and then try successively larger types from <code>Integer</code> to
 * <code>BigInteger</code> and from <code>Float</code> to
 * <code>BigDecimal</code>.</p>
 *
 * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it
 * will be interpreted as a hexadecimal integer.  Values with leading
 * <code>0</code>'s will not be interpreted as octal.</p>
 *
 * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
 *
 * <p>This method does not trim the input string, i.e., strings with leading
 * or trailing spaces will generate NumberFormatExceptions.</p>
 *
 * @param str  String containing a number, may be null
 * @return Number created from the string
 * @throws NumberFormatException if the value cannot be converted
 *///from ww  w.  ja v  a2s.  com
public static Number createNumber(String str) throws NumberFormatException {
    if (str == null) {
        return null;
    }
    if (StringUtils.isBlank(str)) {
        throw new NumberFormatException("A blank string is not a valid number");
    }
    if (str.startsWith("--")) {
        // this is protection for poorness in java.lang.BigDecimal.
        // it accepts this as a legal value, but it does not appear 
        // to be in specification of class. OS X Java parses it to 
        // a wrong value.
        return null;
    }
    if (str.startsWith("0x") || str.startsWith("-0x")) {
        return createInteger(str);
    }
    char lastChar = str.charAt(str.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = str.indexOf('.');
    int expPos = str.indexOf('e') + str.indexOf('E') + 1;

    if (decPos > -1) {

        if (expPos > -1) {
            if (expPos < decPos || expPos > str.length()) {
                throw new NumberFormatException(str + " is not a valid number.");
            }
            dec = str.substring(decPos + 1, expPos);
        } else {
            dec = str.substring(decPos + 1);
        }
        mant = str.substring(0, decPos);
    } else {
        if (expPos > -1) {
            if (expPos > str.length()) {
                throw new NumberFormatException(str + " is not a valid number.");
            }
            mant = str.substring(0, expPos);
        } else {
            mant = str;
        }
        dec = null;
    }
    if (!Character.isDigit(lastChar) && lastChar != '.') {
        if (expPos > -1 && expPos < str.length() - 1) {
            exp = str.substring(expPos + 1, str.length() - 1);
        } else {
            exp = null;
        }
        //Requesting a specific type..
        String numeric = str.substring(0, str.length() - 1);
        boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
        switch (lastChar) {
        case 'l':
        case 'L':
            if (dec == null && exp == null
                    && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
                try {
                    return createLong(numeric);
                } catch (NumberFormatException nfe) {
                    //Too big for a long
                }
                return createBigInteger(numeric);

            }
            throw new NumberFormatException(str + " is not a valid number.");
        case 'f':
        case 'F':
            try {
                Float f = NumberUtils.createFloat(numeric);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    //If it's too big for a float or the float value = 0 and the string
                    //has non-zeros in it, then float does not have the precision we want
                    return f;
                }

            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }
            //$FALL-THROUGH$
        case 'd':
        case 'D':
            try {
                Double d = NumberUtils.createDouble(numeric);
                if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }
            try {
                return createBigDecimal(numeric);
            } catch (NumberFormatException e) {
                // ignore the bad number
            }
            //$FALL-THROUGH$
        default:
            throw new NumberFormatException(str + " is not a valid number.");

        }
    } else {
        //User doesn't have a preference on the return type, so let's start
        //small and go from there...
        if (expPos > -1 && expPos < str.length() - 1) {
            exp = str.substring(expPos + 1, str.length());
        } else {
            exp = null;
        }
        if (dec == null && exp == null) {
            //Must be an int,long,bigint
            try {
                return createInteger(str);
            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }
            try {
                return createLong(str);
            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }
            return createBigInteger(str);

        } else {
            //Must be a float,double,BigDec
            boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
            try {
                Float f = createFloat(str);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    return f;
                }
            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }
            try {
                Double d = createDouble(str);
                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // ignore the bad number
            }

            return createBigDecimal(str);

        }
    }
}

From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java

private XYZDataset getBubbleChartData(SimpleFeatureCollection features, String xField, String yField,
        String sizeField) {//from w ww .  j av  a  2  s . co m
    DefaultXYZDataset2 xyzDataset = new DefaultXYZDataset2();

    // 1. prepare bubble size
    minMaxVisitor.visit(features, xField, yField, sizeField);

    final double minVal = minMaxVisitor.getMinZ();
    final double maxVal = minMaxVisitor.getMaxZ();
    final double diffVal = maxVal - minVal;
    final double scale = Math.min(minMaxVisitor.getMaxX(), minMaxVisitor.getMaxY()) / 8d;

    // 2. calculate x, y, z values
    final int featureCount = features.size();
    double[] xAxis = new double[featureCount];
    double[] yAxis = new double[featureCount];
    double[] zAxis = new double[featureCount];
    String[] featureIDS = new String[featureCount];

    Expression xExpression = ff.property(xField);
    Expression yExpression = ff.property(yField);
    Expression sizeExpression = ff.property(sizeField);

    int index = 0;
    SimpleFeatureIterator featureIter = features.features();
    try {
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();
            featureIDS[index] = feature.getID();

            Double xVal = xExpression.evaluate(feature, Double.class);
            if (xVal == null || xVal.isNaN() || xVal.isInfinite()) {
                continue;
            }

            Double yVal = yExpression.evaluate(feature, Double.class);
            if (yVal == null || yVal.isNaN() || yVal.isInfinite()) {
                continue;
            }

            Double sizeVal = sizeExpression.evaluate(feature, Double.class);
            if (sizeVal == null || sizeVal.isNaN() || sizeVal.isInfinite()) {
                continue;
            }

            xAxis[index] = xVal;
            yAxis[index] = yVal;

            double transformed = 0;
            if (diffVal != 0) {
                transformed = (sizeVal - minVal) / diffVal;
            }

            zAxis[index] = transformed * scale;
            index++;
        }
    } finally {
        featureIter.close();
    }

    xyzDataset.addSeries(EMPTY, new double[][] { xAxis, yAxis, zAxis });
    xyzDataset.addFeatrureIDS(EMPTY, featureIDS);

    return xyzDataset;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java

private BigDecimal getDifference(BigDecimal lessonHours, BigDecimal summaryHours) {
    Double difference;
    difference = (1 - ((lessonHours.doubleValue() - summaryHours.doubleValue()) / lessonHours.doubleValue()))
            * 100;/* www . j a  v  a  2s . c  o m*/
    if (difference.isNaN() || difference.isInfinite()) {
        difference = 0.0;
    }
    return BigDecimal.valueOf(difference).setScale(2, RoundingMode.HALF_UP);
}

From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java

public boolean isDouble(String input) {
    try {/*from  ww w. j a v a 2 s.com*/
        Double v = Double.parseDouble(input);
        if (v.isNaN() || v.isInfinite()) {
            return false;
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.jakz.common.JSONObject.java

/**
 * Try to convert a string into a number, boolean, or null. If the string
 * can't be converted, return the string.
 *
 * @param string/*from  w  w  w.j ava 2 s.c o  m*/
 *            A String.
 * @return A simple JSON value.
 */
public static Object stringToValue(String string) {
    if (string.equals("")) {
        return string;
    }
    if (string.equalsIgnoreCase("true")) {
        return Boolean.TRUE;
    }
    if (string.equalsIgnoreCase("false")) {
        return Boolean.FALSE;
    }
    if (string.equalsIgnoreCase("null")) {
        return JSONObject.NULL;
    }

    /*
     * If it might be a number, try converting it. If a number cannot be
     * produced, then the value will just be a string.
     */

    char initial = string.charAt(0);
    if ((initial >= '0' && initial <= '9') || initial == '-') {
        try {
            if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1
                    || "-0".equals(string)) {
                Double d = Double.valueOf(string);
                if (!d.isInfinite() && !d.isNaN()) {
                    return d;
                }
            } else {
                Long myLong = new Long(string);
                if (string.equals(myLong.toString())) {
                    if (myLong.longValue() == myLong.intValue()) {
                        return Integer.valueOf(myLong.intValue());
                    }
                    return myLong;
                }
            }
        } catch (Exception ignore) {
        }
    }
    return string;
}

From source file:de.bund.bfr.knime.pmm.common.chart.Plotable.java

private boolean isValidValue(Double value) {
    return value != null && !value.isNaN() && !value.isInfinite();
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private boolean isValid(Double value) {
    return value != null && !value.isInfinite() && !value.isNaN();
}