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:Main.java

public static void main(String[] args) {
    Double double1 = new Double(1 / 0.0);

    System.out.println(double1.isInfinite());

}

From source file:Main.java

public static void main(String args[]) {
    Double d1 = new Double(1 / 0.);
    Double d2 = new Double(0 / 0.);

    System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
    System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}

From source file:MainClass.java

public static void main(String args[]) {
    Double d1 = new Double(1 / 0.);
    Double d2 = new Double(0 / 0.);
    System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
    System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}

From source file:org.spantus.math.dtw.abeel.dtw.AbeelDTW.java

private static TimeWarpInfo constrainedTimeWarp(TimeSeries tsI, TimeSeries tsJ, SearchWindow window) {
    CostMatrix costMatrix = createCostMatrix(tsI, tsJ, window);

    int maxI = tsI.size() - 1;
    int maxJ = tsJ.size() - 1;

    Double minimumCost = costMatrix.get(maxI, maxJ);
    if (minimumCost.isInfinite()) {
        return new TimeWarpInfo(minimumCost, null);
    }/*from  www .j ava2s. c om*/
    WarpPath minCostPath = new WarpPath((maxI + maxJ) - 1);
    int i = maxI;
    int j = maxJ;
    minCostPath.addFirst(i, j);
    for (; i > 0 || j > 0; minCostPath.addFirst(i, j)) {
        Map<Pair<Integer, Integer>, Double> localConstraints = window.getLocalConstaints()
                .createLocalConstraints(i, j);
        debug("[constrainedTimeWarp] [{1};{2}]localConstraints: {0}", localConstraints, i, j);
        //remove previous values. This happens due constraints.
        //            if(localConstraints.containsKey(new Pair<Integer,Integer>(i,j)) ){
        //                localConstraints.remove(new Pair<Integer,Integer>(i,j));
        //                localConstraints.put(new Pair<Integer,Integer>(0,0),null);
        //            }

        //            for (Pair<Integer, Integer> pair : localConstraints.keySet()) {
        //            if(j == pair.snd() ){
        //               localConstraints.containsKey(new Pair<Integer,Integer>(i,j));
        //            }
        //         }
        //            if(j==0){
        //               localConstraints.containsKey(new Pair<Integer,Integer>(i,j));
        //            }

        DtwCalculationCtx values = extractConstraintValues(localConstraints, costMatrix);
        debug("[constrainedTimeWarp] min:{1}; extractConstraintValues: {0}", values.getLocalValues(),
                values.getMinPair());
        Pair<Integer, Integer> nextStep = values.getMinPair();

        if (nextStep == null) {
            break;
        }
        i = nextStep.fst();
        j = nextStep.snd();
    }
    minCostPath.addFirst(0, 0);

    TimeWarpInfo timeWarpInfo = new TimeWarpInfo(minimumCost, minCostPath);

    //this can be too big and too slow?
    Pair<StatisticalSummary, RealMatrix> resultCostMatrix = transformCostMatrix(costMatrix, maxI, maxJ);
    timeWarpInfo.setStatisticalSummary(resultCostMatrix.fst());
    timeWarpInfo.setCostMatrix(resultCostMatrix.snd());

    costMatrix.freeMem();

    return timeWarpInfo;
}

From source file:org.spantus.math.dtw.abeel.dtw.AbeelDTW.java

private static Pair<StatisticalSummary, RealMatrix> transformCostMatrix(CostMatrix costMatrix, int maxI,
        int maxJ) {
    Array2DRowRealMatrix resultCostMatrix = new Array2DRowRealMatrix(maxJ, maxI);
    SummaryStatistics stats = new SummaryStatistics();
    for (int i = 0; i < maxI; i++) {
        for (int j = 0; j < maxJ; j++) {
            //Abeel and Apache has different oreder understanding:
            //Abeel: col, row
            Double val = costMatrix.get(i, j);
            //Apache row, col
            resultCostMatrix.setEntry(j, i, val);
            if (!val.isInfinite()) {
                stats.addValue(val);
            }/*  ww w .  j  av  a  2s .com*/
        }
    }
    return new Pair<StatisticalSummary, RealMatrix>(stats, resultCostMatrix);
}

From source file:Main.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 hold 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>
 *
 * @param val String containing a number
 * @return Number created from the string
 * @throws NumberFormatException if the value cannot be converted
 *//*from  www . j  a v a  2s. c om*/
public static Number createNumber(String val) throws NumberFormatException {
    if (val == null) {
        return null;
    }
    if (val.length() == 0) {
        throw new NumberFormatException("\"\" is not a valid number.");
    }
    if (val.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 (val.startsWith("0x") || val.startsWith("-0x")) {
        return createInteger(val);
    }
    char lastChar = val.charAt(val.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = val.indexOf('.');
    int expPos = val.indexOf('e') + val.indexOf('E') + 1;

    if (decPos > -1) {

        if (expPos > -1) {
            if (expPos < decPos) {
                throw new NumberFormatException(val + " is not a valid number.");
            }
            dec = val.substring(decPos + 1, expPos);
        } else {
            dec = val.substring(decPos + 1);
        }
        mant = val.substring(0, decPos);
    } else {
        if (expPos > -1) {
            mant = val.substring(0, expPos);
        } else {
            mant = val;
        }
        dec = null;
    }
    if (!Character.isDigit(lastChar)) {
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length() - 1);
        } else {
            exp = null;
        }
        //Requesting a specific type..
        String numeric = val.substring(0, val.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(val + " is not a valid number.");
        case 'f':
        case 'F':
            try {
                Float f = 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 e) {
                // ignore the bad number
            }
            //Fall through
        case 'd':
        case 'D':
            try {
                Double d = createDouble(numeric);
                if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createBigDecimal(numeric);
            } catch (NumberFormatException e) {
                // empty catch
            }
            //Fall through
        default:
            throw new NumberFormatException(val + " 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 < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length());
        } else {
            exp = null;
        }
        if (dec == null && exp == null) {
            //Must be an int,long,bigint
            try {
                return createInteger(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createLong(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            return createBigInteger(val);

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

            return createBigDecimal(val);

        }

    }
}

From source file:de.cebitec.readXplorer.plotting.CreatePlots.java

public synchronized static ChartPanel createInfPlot(Map<PersistentFeature, Pair<Double, Double>> data,
        String xName, String yName, XYToolTipGenerator toolTip) {
    XYSeriesCollection normal = new XYSeriesCollection();
    XYSeriesCollection posInf = new XYSeriesCollection();
    XYSeriesCollection negInf = new XYSeriesCollection();
    XYSeries nor = new XYSeries("Normal");
    XYSeries pos = new XYSeries("Positive Infinite");
    XYSeries neg = new XYSeries("Negative Infinite");
    for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) {
        PersistentFeature key = it.next();
        Pair<Double, Double> pair = data.get(key);
        Double X = pair.getFirst();
        Double Y = pair.getSecond();

        if (Y == Double.POSITIVE_INFINITY) {
            Y = 0d;/*from w  ww  .jav  a2  s.  c  o m*/
            pos.add(new PlotDataItem(key, X, Y));
        }
        if (Y == Double.NEGATIVE_INFINITY) {
            Y = 0d;
            neg.add(new PlotDataItem(key, X, Y));
        }
        if (!Y.isInfinite() && !X.isInfinite()) {
            nor.add(new PlotDataItem(key, X, Y));
        }
    }
    normal.addSeries(nor);
    posInf.addSeries(pos);
    negInf.addSeries(neg);
    JFreeChart chart = createCombinedChart(normal, posInf, negInf, xName, yName, toolTip);
    chart.removeLegend();
    ChartPanel panel = new ChartPanel(chart, true, false, true, true, true);
    panel.setInitialDelay(0);
    panel.setMaximumDrawHeight(1080);
    panel.setMaximumDrawWidth(1920);
    panel.setMouseWheelEnabled(true);
    panel.setMouseZoomable(true);
    MouseActions mouseAction = new MouseActions();
    panel.addChartMouseListener(mouseAction);
    ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction);
    panel.addOverlay(overlay);
    return panel;
}

From source file:de.cosmocode.collections.utility.Convert.java

private static Double doIntoDouble(Object value) {
    if (value == null)
        return null;
    if (value instanceof Double)
        return Double.class.cast(value);
    if (value instanceof Number)
        return Number.class.cast(value).doubleValue();
    final String s = doIntoString(value);
    try {//w w w  .ja  v  a 2s. co m
        final Double d = Double.valueOf(s);
        LOG.debug("Converted {} into {}", value, d);
        if (d.isInfinite() || d.isNaN())
            return null;
        return d;
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:ml.shifu.shifu.core.Normalizer.java

/**
 * Check specified standard deviation cutoff and return the correct value.
 * /*  w ww . j av a2 s  .c  o  m*/
 * @param cutoff
 *            specified standard deviation cutoff
 * @return If cutoff is valid then return it, else return {@link Normalizer#STD_DEV_CUTOFF}
 */
public static double checkCutOff(Double cutoff) {
    double stdDevCutOff;
    if (cutoff != null && !cutoff.isInfinite() && !cutoff.isNaN()) {
        stdDevCutOff = cutoff;
    } else {
        stdDevCutOff = STD_DEV_CUTOFF;
    }

    return stdDevCutOff;
}

From source file:org.deidentifier.arx.gui.view.SWTUtil.java

/**
 * Adds a bar chart to a column//ww  w . j  a  v  a 2 s .c om
 * @param table
 * @param column
 */
public static void createColumnWithBarCharts(final Table table, final TableColumn column) {

    int index = -1;
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (table.getColumn(i) == column) {
            index = i;
            break;
        }
    }
    if (index == -1) {
        return;
    }
    final Display display = table.getDisplay();
    final int columnIndex = index;
    table.addListener(SWT.PaintItem, new Listener() {
        @Override
        public void handleEvent(Event event) {
            if (event.index == columnIndex) {
                GC gc = event.gc;
                TableItem item = (TableItem) event.item;
                Object object = item.getData(String.valueOf(columnIndex));
                if (object == null || !(object instanceof Double)) {
                    return;
                }

                // Store
                Color foreground = gc.getForeground();
                Color background = gc.getBackground();

                // Draw NaN
                Double percent = (Double) object;
                if (percent.isNaN() || percent.isInfinite()) {
                    String text = percent.isNaN() ? "NaN" : "Infinite";
                    gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
                    Point size = event.gc.textExtent(text);
                    int offset = Math.max(0, (event.height - size.y) / 2);
                    gc.drawText(text, event.x + 2, event.y + offset, true);

                    // Draw value
                } else {

                    // Initialize
                    String text = SWTUtil.getPrettyString((Double) object * 100d) + "%";
                    percent = percent >= 0d ? percent : 0d;
                    percent = percent <= 1d ? percent : 1d;

                    // Draw bar
                    gc.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
                    gc.setForeground(GUIHelper.getColor(240, 240, 240));
                    int width = (int) Math.round((column.getWidth() - 1) * percent);
                    width = width >= 1 ? width : 1;
                    gc.fillGradientRectangle(event.x, event.y, width, event.height, true);

                    // Draw border
                    Rectangle rect2 = new Rectangle(event.x, event.y, width - 1, event.height - 1);
                    gc.setForeground(GUIHelper.getColor(150, 150, 150));
                    gc.drawRectangle(rect2);

                    // Draw text
                    gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
                    Point size = event.gc.textExtent(text);
                    int offset = Math.max(0, (event.height - size.y) / 2);
                    gc.drawText(text, event.x + 2, event.y + offset, true);
                }

                // Reset
                gc.setForeground(background);
                gc.setBackground(foreground);
            }
        }
    });
}