Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

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

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Compute the global minimum and maximum pixel values of an input ImageJ
 * {@code ImagePlus} object. The min and max values are computed over all
 * slices of an image. If {@code image} is null, the return value is null.
 *
 * @param image input {@code ImagePlus} object
 * @return two-element {@code double} array whose first value is the global
 *         minimum pixel value and whose second value is the global maximum
 *         pixel value of {@code image}. Null value is returned for null
 *         input./* w w  w.j av a2s  .  c o m*/
 */
public static final double[] getGlobalMinAndMax(ImagePlus image) {
    double[] minAndMax = null;

    if (image != null) {
        double globalMin = Double.POSITIVE_INFINITY;
        double globalMax = Double.NEGATIVE_INFINITY;
        int stackSize = image.getStackSize();
        ImageStack stack = image.getStack();
        for (int slice = 1; slice <= stackSize; slice++) {
            ImageProcessor processor = stack.getProcessor(slice);
            double min = processor.getMin();
            double max = processor.getMax();
            if (min < globalMin) {
                globalMin = min;
            }
            if (max > globalMax) {
                globalMax = max;
            }
        }
        minAndMax = new double[] { globalMin, globalMax };
    }

    return minAndMax;
}

From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java

private Boolean checkNormParameters(NormalizationConfiguration normConfig) {
    if (!normConfig.isIntegrate()) {
        if (normConfig.getAtPointXValue() == null || normConfig.getAtPointYValue() == null
                || !isNumeric(normConfig.getAtPointXValue().toString())
                || !isNumeric(normConfig.getAtPointYValue().toString()) || normConfig.getAtPointXValue() <= 0
                || normConfig.getAtPointYValue() <= 0) {
            NarrowOptionPane.showMessageDialog(null, "Invalid (X, Y) values.", "ERROR",
                    NarrowOptionPane.ERROR_MESSAGE);
            return false;
        }/*from w w  w  . j  a  v  a2  s .  co m*/

    } else {
        if (normConfig.getYValue() == null || !isNumeric(normConfig.getYValue().toString())
                || normConfig.getYValue() <= 0) {
            NarrowOptionPane.showMessageDialog(this, "Invalid Y value.", "ERROR",
                    NarrowOptionPane.ERROR_MESSAGE);
            return false;
        }

        if (normConfig.getXmax() == null || normConfig.getXmin() == null || normConfig.getXmax() <= 0
                || normConfig.getXmax() <= normConfig.getXmin()) {
            NarrowOptionPane.showMessageDialog(this, "Invalid range values.", "ERROR",
                    NarrowOptionPane.ERROR_MESSAGE);
            return false;
        }
        if (!normConfig.getXmin().equals(Double.NEGATIVE_INFINITY) && normConfig.getXmin() <= 0) {
            NarrowOptionPane.showMessageDialog(this, "Invalid range values.", "ERROR",
                    NarrowOptionPane.ERROR_MESSAGE);
            return false;
        }
    }

    return true;
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils.NumberObject}
 *//*  ww  w . jav a 2 s. co  m*/
@SuppressWarnings("unchecked")
@Test
public void NumberObjectTest() {
    try {
        Class<?> numberObject = ClassLoader.getSystemClassLoader()
                .loadClass(NumberUtils.class.getName() + "$NumberObject");

        Constructor<?> c = numberObject.getDeclaredConstructor(Class.class);
        c.setAccessible(true);

        Method ofType = numberObject.getMethod("of", Class.class);
        ofType.setAccessible(true);

        Method ofN = numberObject.getMethod("of", Number.class);
        ofN.setAccessible(true);

        Method parsable = numberObject.getDeclaredMethod("parsable", Number.class);
        parsable.setAccessible(true);

        Method contains = numberObject.getDeclaredMethod("contains", Number.class);
        contains.setAccessible(true);

        Method valueOf = numberObject.getDeclaredMethod("valueOf", Number.class);
        valueOf.setAccessible(true);

        for (Class<?> type : NUMBERS) {
            Object o = c.newInstance(type);
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            Object numob = ofType.invoke(null, type);
            assertEquals("ofType: " + type.getSimpleName(), o, numob);
            Number n = null;
            if (!type.isPrimitive()) {
                if (ClassUtils.isPrimitiveWrapper(type)) {
                    n = (Number) ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class)
                            .invoke(null, "1");
                } else {
                    n = (Number) type.getField("ONE").get(null);
                }
                if (type.equals(byte.class))
                    assertEquals("ofN: 1: " + type.getSimpleName(), o, ofN.invoke(null, n));
            }
            assertEquals("parsable: -1: " + type.getSimpleName(), true, parsable.invoke(numob, -1));
            assertEquals("parsable: 0: " + type.getSimpleName(), true, parsable.invoke(numob, 0));
            assertEquals("parsable: 1: " + type.getSimpleName(), true, parsable.invoke(numob, 1));

            assertEquals("parsable: null: " + type.getSimpleName(), !type.isPrimitive(),
                    parsable.invoke(numob, (Number) null));

            Object expected = ObjectUtils.isAny(wrapper, Float.class, Double.class, BigDecimal.class,
                    BigInteger.class);
            assertEquals("parsable: Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE));
            assertEquals("parsable: Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.toBigInteger()));
            assertEquals("parsable: Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT));
            assertEquals("parsable: Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.toBigInteger()));
            assertEquals("parsable: -Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate()));
            assertEquals("parsable: -Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate().toBigInteger()));
            assertEquals("parsable: -Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate()));
            assertEquals("parsable: -Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate().toBigInteger()));

            expected = ObjectUtils.isAny(wrapper, Float.class, Double.class);
            assertEquals("parsable: NaN: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NaN));
            assertEquals("parsable: NaN: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NaN));

            if (Byte.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 1234.56f));
            }
            if (Short.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 12345.6f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 123456.789f));
            }
            if (Integer.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123456.789f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456d));
            }
            if (Long.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456f));
            }
            if (Float.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, -Double.MAX_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Double.MAX_VALUE));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, -Double.MAX_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Double.MAX_VALUE));
            }
            if (Double.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));
            }
            if (!ClassUtils.isPrimitiveWrapper(wrapper)) {
                assertEquals("parsable: fraction: " + type.getSimpleName(), BigDecimal.class.equals(type),
                        parsable.invoke(numob, 123.456f));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
            }

            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "123");
            } else {
                expected = new BigDecimal("123");
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            for (Class<?> valueType : OBJECTS) {
                if (ClassUtils.isPrimitiveWrapper(valueType)) {
                    n = (Number) valueType.getMethod("valueOf", String.class).invoke(null, "123");
                } else {
                    n = new BigDecimal("123");
                    if (BigInteger.class.equals(valueType))
                        n = ((BigDecimal) n).toBigInteger();
                }
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        expected, valueOf.invoke(numob, n));
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: "
                                + type.getSimpleName(),
                        expected.getClass(), valueOf.invoke(numob, n).getClass());
            }

            n = 123.456f;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Float) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = 1.23456789E-6d;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Double) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2);
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: " + type.getSimpleName(), expected, valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2).negate();
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: negative: " + type.getSimpleName(), expected,
                    valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: negative: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

From source file:gda.plots.SimplePlot.java

/**
 * @param collection/*from ww  w  .j a  v a 2 s.  c om*/
 * @param includeInterval
 * @return range for the range axis Y
 */
public Range getRangeBounds(SimpleXYSeriesCollection collection,
        @SuppressWarnings("unused") boolean includeInterval) {
    if (!isTurboMode())
        return null;

    Range domainBounds = null;
    Range rangeBounds = null;
    if (collection == leftSeriesCollection) {
        domainBounds = leftDomainBounds;
        rangeBounds = leftRangeBounds;
    } else if (collection == rightSeriesCollection) {
        domainBounds = rightDomainBounds;
        rangeBounds = rightRangeBounds;
    }
    if (rangeBounds != null)
        return rangeBounds;

    Double min = Double.POSITIVE_INFINITY;
    Double max = Double.NEGATIVE_INFINITY;

    if (isStripMode()) {
        synchronized (linesChanged) {
            if (linesChanged.size() == 0)
                return null;
            Iterator<Integer> iter = linesChanged.iterator();
            while (iter.hasNext()) {
                SimpleXYSeries sxys = collection.find(iter.next());
                // is it in this collection?
                if (sxys != null && sxys.isVisible()) {

                    Double sxys_min, sxys_max;
                    Double sxys_Xmax = sxys.getMaxX();
                    if (Double.isInfinite(sxys_Xmax))
                        return null;
                    /*
                     * create range in data units over which we want to get the y min and max
                     */
                    SimpleValueTransformer valTrans = collection.getXValueTransformer();
                    Double maxXTransformed = valTrans.transformValue(sxys_Xmax);
                    double minX = valTrans.transformValueBack(maxXTransformed - stripWidth);
                    Double[] extents = sxys.getBounds(new Range(minX, sxys_Xmax));
                    sxys_min = extents[2];
                    sxys_max = extents[3];
                    if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max))
                        return null;
                    min = Math.min(min, sxys_min);
                    max = Math.max(max, sxys_max);
                }

            }
        }
    } else {
        for (Object obj : collection.getSeries()) {
            if (obj != null && obj instanceof SimpleXYSeries) {
                SimpleXYSeries sxys = (SimpleXYSeries) obj;
                if (sxys.isVisible()) {
                    if (domainBounds == null) {
                        double sxys_min, sxys_max;
                        sxys_min = sxys.getMinY();
                        sxys_max = sxys.getMaxY();
                        min = Math.min(min, sxys_min);
                        max = Math.max(max, sxys_max);
                    } else {
                        double sxys_min, sxys_max;
                        Double[] extents = sxys.getBounds(domainBounds);
                        sxys_min = extents[2];
                        sxys_max = extents[3];
                        if (Double.isInfinite(sxys_min) || Double.isInfinite(sxys_max))
                            return null;
                        min = Math.min(min, sxys_min);
                        max = Math.max(max, sxys_max);
                    }
                }
            }
        }
    }
    if (Double.isInfinite(min) || Double.isInfinite(max))
        return null;

    Range newRange = new Range(min, max);
    if (collection == leftSeriesCollection)
        lastRangeBoundsLeft = newRange;
    if (collection == rightSeriesCollection)
        lastRangeBoundsRight = newRange;
    return newRange;
}

From source file:gda.plots.SimplePlot.java

/**
 * @param collection//from   w w  w.jav  a  2 s  . c  om
 * @param includeInterval
 * @return range for the domain axis X
 */
public Range getDomainBounds(SimpleXYSeriesCollection collection,
        @SuppressWarnings("unused") boolean includeInterval) {
    Double min = Double.POSITIVE_INFINITY;
    Double max = Double.NEGATIVE_INFINITY;
    if (!isTurboMode())
        return null;

    if (collection == leftSeriesCollection && leftDomainBounds != null)
        return leftDomainBounds;
    if (collection == rightSeriesCollection && rightDomainBounds != null)
        return rightDomainBounds;

    if (isStripMode()) {
        /*
         * In stripMode get max of changed lines - min will be the max minus the stripWidth
         */
        synchronized (linesChanged) {
            if (linesChanged.size() == 0)
                return null;
            Iterator<Integer> iter = linesChanged.iterator();
            while (iter.hasNext()) {
                SimpleXYSeries sxys = collection.find(iter.next());
                // is it in this collection?
                if (sxys != null && sxys.isVisible()) {
                    double sxys_max;
                    sxys_max = sxys.getMaxX();
                    max = Math.max(max, sxys_max);
                }

            }
            min = max; //we remove the stripWidth later as stripWidth is in final units after transformation
        }
    } else {
        /*
         * go through all visible lines are get min and max
         */
        for (Object obj : collection.getSeries()) {
            if (obj != null && obj instanceof SimpleXYSeries) {
                SimpleXYSeries sxys = (SimpleXYSeries) obj;
                if (sxys.isVisible()) {
                    double sxys_min, sxys_max;
                    sxys_min = sxys.getMinX();
                    sxys_max = sxys.getMaxX();
                    min = Math.min(min, sxys_min);
                    max = Math.max(max, sxys_max);
                }
            }
        }
    }
    if (Double.isInfinite(min) || Double.isInfinite(max))
        return null;
    SimpleValueTransformer valTrans = collection.getXValueTransformer();
    Double maxTransformed = valTrans.transformValue(max);
    Double minTransformed = stripWidth != null ? maxTransformed - stripWidth : valTrans.transformValue(min);
    Range newRange = new Range(minTransformed, maxTransformed);

    if (collection == leftSeriesCollection)
        lastDomainBoundsLeft = newRange;
    if (collection == rightSeriesCollection)
        lastDomainBoundsRight = newRange;
    return newRange;
}

From source file:com.facebook.presto.tests.AbstractTestQueries.java

@Test
public void testValuesWithNonTrivialType() throws Exception {
    MaterializedResult actual = computeActual("VALUES (0.0/0.0, 1.0/0.0, -1.0/0.0)");

    List<MaterializedRow> rows = actual.getMaterializedRows();
    assertEquals(rows.size(), 1);//from   w  ww.ja v a 2  s .  com

    MaterializedRow row = rows.get(0);
    assertTrue(((Double) row.getField(0)).isNaN());
    assertEquals(row.getField(1), Double.POSITIVE_INFINITY);
    assertEquals(row.getField(2), Double.NEGATIVE_INFINITY);
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Normalize a GTS, replacing X by (X-MIN)/(MAX-MIN) or 1.0
 * @param gts/*from   ww  w. jav a 2  s  .  c om*/
 * @return
 */
public static GeoTimeSerie normalize(GeoTimeSerie gts) {
    //
    // Return immediately if GTS is not numeric or has no values
    //
    if ((TYPE.DOUBLE != gts.getType() && TYPE.LONG != gts.getType()) || 0 == gts.values) {
        return gts.clone();
    }

    //
    // Extract min/max
    //

    double dmin = Double.POSITIVE_INFINITY;
    double dmax = Double.NEGATIVE_INFINITY;

    long lmin = Long.MAX_VALUE;
    long lmax = Long.MIN_VALUE;

    if (TYPE.LONG == gts.getType()) {
        for (int i = 0; i < gts.values; i++) {
            long value = (long) GTSHelper.valueAtIndex(gts, i);

            if (value > lmax) {
                lmax = value;
            }
            if (value < lmin) {
                lmin = value;
            }
        }
    } else {
        for (int i = 0; i < gts.values; i++) {
            double value = (double) GTSHelper.valueAtIndex(gts, i);

            if (value > dmax) {
                dmax = value;
            }
            if (value < dmin) {
                dmin = value;
            }
        }
    }

    boolean constant = false;

    if (lmin == lmax || dmin == dmax) {
        constant = true;
    }

    //
    // Don't use clone or cloneEmpty, this would force the type to that of 'gts'

    GeoTimeSerie normalized = new GeoTimeSerie(gts.lastbucket, gts.bucketcount, gts.bucketspan, gts.values);
    normalized.setName(gts.getName());
    normalized.setLabels(gts.getLabels());

    for (int i = 0; i < gts.values; i++) {
        Object value;

        if (constant) {
            value = 1.0D;
        } else if (TYPE.LONG == gts.getType()) {
            value = ((long) GTSHelper.valueAtIndex(gts, i) - lmin) / (double) (lmax - lmin);
        } else {
            value = ((double) GTSHelper.valueAtIndex(gts, i) - dmin) / (double) (dmax - dmin);
        }

        GTSHelper.setValue(normalized, gts.ticks[i], GTSHelper.locationAtIndex(gts, i),
                GTSHelper.elevationAtIndex(gts, i), value, false);
    }

    return normalized;
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Normalize a GTS, replacing X by (X-MEAN)/(MAX-MIN) or 1.0
 * @param gts//  w  w  w  . j av a 2 s  . com
 * @return
 */
public static GeoTimeSerie isonormalize(GeoTimeSerie gts) {
    //
    // Return immediately if GTS is not numeric or has no values
    //
    if ((TYPE.DOUBLE != gts.getType() && TYPE.LONG != gts.getType()) || 0 == gts.values) {
        return gts.clone();
    }

    //
    // Extract min/max
    //

    double sum = 0.0D;

    double dmin = Double.POSITIVE_INFINITY;
    double dmax = Double.NEGATIVE_INFINITY;

    long lmin = Long.MAX_VALUE;
    long lmax = Long.MIN_VALUE;

    if (TYPE.LONG == gts.getType()) {
        for (int i = 0; i < gts.values; i++) {
            long value = (long) GTSHelper.valueAtIndex(gts, i);

            if (value > lmax) {
                lmax = value;
            }
            if (value < lmin) {
                lmin = value;
            }

            sum += value;
        }
    } else {
        for (int i = 0; i < gts.values; i++) {
            double value = (double) GTSHelper.valueAtIndex(gts, i);

            if (value > dmax) {
                dmax = value;
            }
            if (value < dmin) {
                dmin = value;
            }

            sum += value;
        }
    }

    boolean constant = false;

    if (lmin == lmax || dmin == dmax) {
        constant = true;
    }

    //
    // Don't use clone or cloneEmpty, this would force the type to that of 'gts'

    GeoTimeSerie isonormalized = new GeoTimeSerie(gts.lastbucket, gts.bucketcount, gts.bucketspan, gts.values);
    isonormalized.setName(gts.getName());
    isonormalized.setLabels(gts.getLabels());

    double mean = sum / gts.values;

    for (int i = 0; i < gts.values; i++) {
        Object value;

        if (constant) {
            value = 1.0D;
        } else if (TYPE.LONG == gts.getType()) {
            value = ((long) GTSHelper.valueAtIndex(gts, i) - mean) / (double) (lmax - lmin);
        } else {
            value = ((double) GTSHelper.valueAtIndex(gts, i) - mean) / (double) (dmax - dmin);
        }

        GTSHelper.setValue(isonormalized, gts.ticks[i], GTSHelper.locationAtIndex(gts, i),
                GTSHelper.elevationAtIndex(gts, i), value, false);
    }

    return isonormalized;
}

From source file:io.prestosql.tests.AbstractTestQueries.java

@Test
public void testValuesWithNonTrivialType() {
    MaterializedResult actual = computeActual("VALUES (0E0/0E0, 1E0/0E0, -1E0/0E0)");

    List<MaterializedRow> rows = actual.getMaterializedRows();
    assertEquals(rows.size(), 1);//ww  w.j  a v a  2 s. c o  m

    MaterializedRow row = rows.get(0);
    assertTrue(((Double) row.getField(0)).isNaN());
    assertEquals(row.getField(1), Double.POSITIVE_INFINITY);
    assertEquals(row.getField(2), Double.NEGATIVE_INFINITY);
}