Example usage for java.lang Double MIN_VALUE

List of usage examples for java.lang Double MIN_VALUE

Introduction

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

Prototype

double MIN_VALUE

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

Click Source Link

Document

A constant holding the smallest positive nonzero value of type double , 2-1074.

Usage

From source file:com.cfelde.aws.ddb.management.TableThroughput.java

/**
 * Returns number of consumed reads per second.
 *
 * @return Reads per second/*from  ww  w  .  ja  v a 2  s. c o m*/
 */
public double getConsumedReadCapacity() {
    synchronized (lock) {
        GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
        request.setStatistics(Collections.singleton("Sum"));
        request.setDimensions(Arrays.asList(new Dimension().withName("TableName").withValue(tableName)));
        request.setNamespace("AWS/DynamoDB");
        request.setStartTime(new Date(System.currentTimeMillis() - (1000L * period * 5)));
        request.setEndTime(new Date(System.currentTimeMillis() + 60000L));
        request.setPeriod(period);
        request.setMetricName("ConsumedReadCapacityUnits");

        GetMetricStatisticsResult result = client.getMetricStatistics(request);

        if (!result.getDatapoints().isEmpty()) {
            List<Datapoint> dataPoints = new ArrayList<>(result.getDatapoints());

            Collections.sort(dataPoints, new Comparator<Datapoint>() {
                @Override
                public int compare(Datapoint o1, Datapoint o2) {
                    return o2.getTimestamp().compareTo(o1.getTimestamp());
                }
            });

            Datapoint datapoint = dataPoints.get(0);

            consumedReadValues.add(datapoint.getSum() / period);
        } else {
            consumedReadValues.add(0D);
        }

        while (consumedReadValues.size() > maxConsumedCount)
            consumedReadValues.remove(0);

        if (consumedReadValues.isEmpty())
            return 0;

        double maxConsumedValue = Double.MIN_VALUE;
        for (Double c : consumedReadValues) {
            if (c > maxConsumedValue)
                maxConsumedValue = c;
        }

        return maxConsumedValue;
    }
}

From source file:org.renjin.parser.NumericLiterals.java

/**
 * Finds the closest double-precision floating point number to the given decimal string, parsed by
 * {@link #parseDoubleDecimal(CharSequence, int, int, int, char)} above.
 *
 * <p>This implementation is based on OpenJDK's {@code com.sun.misc.FloatingDecimal.ASCIIToBinaryBuffer.doubleValue()},
 * but included here nearly verbatim to avoid a dependency on an internal SDK class. The original code
 * is copyright 1996, 2013, Oracle and/or its affiliates and licensed under the GPL v2.</p></p>
 *
 * @param in the input string/*  w ww .  j  a v a  2s . c  om*/
 * @param sign the sign, -1 or +1, parsed above in {@link #parseDouble(CharSequence, int, int, char, boolean)}
 * @param startIndex the index at which to start parsing
 * @param endIndex the index, exclusive, at which to stop parsing
 * @param decimalPoint the decimal point character to use. Generally either '.' or ','
 * @return the number as a {@code double}, or {@code NA} if the string is malformatted.
 */
public static double doubleValue(boolean isNegative, int decExponent, char[] digits, int nDigits) {
    int kDigits = Math.min(nDigits, MAX_DECIMAL_DIGITS + 1);
    //
    // convert the lead kDigits to a long integer.
    //
    // (special performance hack: start to do it using int)
    int iValue = (int) digits[0] - (int) '0';
    int iDigits = Math.min(kDigits, INT_DECIMAL_DIGITS);
    for (int i = 1; i < iDigits; i++) {
        iValue = iValue * 10 + (int) digits[i] - (int) '0';
    }
    long lValue = (long) iValue;
    for (int i = iDigits; i < kDigits; i++) {
        lValue = lValue * 10L + (long) ((int) digits[i] - (int) '0');
    }
    double dValue = (double) lValue;
    int exp = decExponent - kDigits;
    //
    // lValue now contains a long integer with the value of
    // the first kDigits digits of the number.
    // dValue contains the (double) of the same.
    //

    if (nDigits <= MAX_DECIMAL_DIGITS) {
        //
        // possibly an easy case.
        // We know that the digits can be represented
        // exactly. And if the exponent isn't too outrageous,
        // the whole thing can be done with one operation,
        // thus one rounding error.
        // Note that all our constructors trim all leading and
        // trailing zeros, so simple values (including zero)
        // will always end up here
        //
        if (exp == 0 || dValue == 0.0) {
            return (isNegative) ? -dValue : dValue; // small floating integer
        } else if (exp >= 0) {
            if (exp <= MAX_SMALL_TEN) {
                //
                // Can get the answer with one operation,
                // thus one roundoff.
                //
                double rValue = dValue * SMALL_10_POW[exp];
                return (isNegative) ? -rValue : rValue;
            }
            int slop = MAX_DECIMAL_DIGITS - kDigits;
            if (exp <= MAX_SMALL_TEN + slop) {
                //
                // We can multiply dValue by 10^(slop)
                // and it is still "small" and exact.
                // Then we can multiply by 10^(exp-slop)
                // with one rounding.
                //
                dValue *= SMALL_10_POW[slop];
                double rValue = dValue * SMALL_10_POW[exp - slop];
                return (isNegative) ? -rValue : rValue;
            }
            //
            // Else we have a hard case with a positive exp.
            //
        } else {
            if (exp >= -MAX_SMALL_TEN) {
                //
                // Can get the answer in one division.
                //
                double rValue = dValue / SMALL_10_POW[-exp];
                return (isNegative) ? -rValue : rValue;
            }
            //
            // Else we have a hard case with a negative exp.
            //
        }
    }

    //
    // Harder cases:
    // The sum of digits plus exponent is greater than
    // what we think we can do with one error.
    //
    // Start by approximating the right answer by,
    // naively, scaling by powers of 10.
    //
    if (exp > 0) {
        if (decExponent > MAX_DECIMAL_EXPONENT + 1) {
            //
            // Lets face it. This is going to be
            // Infinity. Cut to the chase.
            //
            return (isNegative) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
        }
        if ((exp & 15) != 0) {
            dValue *= SMALL_10_POW[exp & 15];
        }
        if ((exp >>= 4) != 0) {
            int j;
            for (j = 0; exp > 1; j++, exp >>= 1) {
                if ((exp & 1) != 0) {
                    dValue *= BIG_10_POW[j];
                }
            }
            //
            // The reason for the weird exp > 1 condition
            // in the above loop was so that the last multiply
            // would get unrolled. We handle it here.
            // It could overflow.
            //
            double t = dValue * BIG_10_POW[j];
            if (Double.isInfinite(t)) {
                //
                // It did overflow.
                // Look more closely at the result.
                // If the exponent is just one too large,
                // then use the maximum finite as our estimate
                // value. Else call the result infinity
                // and punt it.
                // ( I presume this could happen because
                // rounding forces the result here to be
                // an ULP or two larger than
                // Double.MAX_VALUE ).
                //
                t = dValue / 2.0;
                t *= BIG_10_POW[j];
                if (Double.isInfinite(t)) {
                    return (isNegative) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
                }
                t = Double.MAX_VALUE;
            }
            dValue = t;
        }
    } else if (exp < 0) {
        exp = -exp;
        if (decExponent < MIN_DECIMAL_EXPONENT - 1) {
            //
            // Lets face it. This is going to be
            // zero. Cut to the chase.
            //
            return (isNegative) ? -0.0 : 0.0;
        }
        if ((exp & 15) != 0) {
            dValue /= SMALL_10_POW[exp & 15];
        }
        if ((exp >>= 4) != 0) {
            int j;
            for (j = 0; exp > 1; j++, exp >>= 1) {
                if ((exp & 1) != 0) {
                    dValue *= TINY_10_POW[j];
                }
            }
            //
            // The reason for the weird exp > 1 condition
            // in the above loop was so that the last multiply
            // would get unrolled. We handle it here.
            // It could underflow.
            //
            double t = dValue * TINY_10_POW[j];
            if (t == 0.0) {
                //
                // It did underflow.
                // Look more closely at the result.
                // If the exponent is just one too small,
                // then use the minimum finite as our estimate
                // value. Else call the result 0.0
                // and punt it.
                // ( I presume this could happen because
                // rounding forces the result here to be
                // an ULP or two less than
                // Double.MIN_VALUE ).
                //
                t = dValue * 2.0;
                t *= TINY_10_POW[j];
                if (t == 0.0) {
                    return (isNegative) ? -0.0 : 0.0;
                }
                t = Double.MIN_VALUE;
            }
            dValue = t;
        }
    }

    //
    // dValue is now approximately the result.
    // The hard part is adjusting it, by comparison
    // with FDBigInteger arithmetic.
    // Formulate the EXACT big-number result as
    // bigD0 * 10^exp
    //
    if (nDigits > MAX_NDIGITS) {
        nDigits = MAX_NDIGITS + 1;
        digits[MAX_NDIGITS] = '1';
    }
    FDBigInteger bigD0 = new FDBigInteger(lValue, digits, kDigits, nDigits);
    exp = decExponent - nDigits;

    long ieeeBits = Double.doubleToRawLongBits(dValue); // IEEE-754 bits of double candidate
    final int B5 = Math.max(0, -exp); // powers of 5 in bigB, value is not modified inside correctionLoop
    final int D5 = Math.max(0, exp); // powers of 5 in bigD, value is not modified inside correctionLoop
    bigD0 = bigD0.multByPow52(D5, 0);
    bigD0.makeImmutable(); // prevent bigD0 modification inside correctionLoop
    FDBigInteger bigD = null;
    int prevD2 = 0;

    correctionLoop: while (true) {
        // here ieeeBits can't be NaN, Infinity or zero
        int binexp = (int) (ieeeBits >>> EXP_SHIFT);
        long bigBbits = ieeeBits & SIGNIF_BIT_MASK;
        if (binexp > 0) {
            bigBbits |= FRACT_HOB;
        } else { // Normalize denormalized numbers.
            assert bigBbits != 0L : bigBbits; // doubleToBigInt(0.0)
            int leadingZeros = Long.numberOfLeadingZeros(bigBbits);
            int shift = leadingZeros - (63 - EXP_SHIFT);
            bigBbits <<= shift;
            binexp = 1 - shift;
        }
        binexp -= EXP_BIAS;
        int lowOrderZeros = Long.numberOfTrailingZeros(bigBbits);
        bigBbits >>>= lowOrderZeros;
        final int bigIntExp = binexp - EXP_SHIFT + lowOrderZeros;
        final int bigIntNBits = EXP_SHIFT + 1 - lowOrderZeros;

        //
        // Scale bigD, bigB appropriately for
        // big-integer operations.
        // Naively, we multiply by powers of ten
        // and powers of two. What we actually do
        // is keep track of the powers of 5 and
        // powers of 2 we would use, then factor out
        // common divisors before doing the work.
        //
        int B2 = B5; // powers of 2 in bigB
        int D2 = D5; // powers of 2 in bigD
        int Ulp2; // powers of 2 in halfUlp.
        if (bigIntExp >= 0) {
            B2 += bigIntExp;
        } else {
            D2 -= bigIntExp;
        }
        Ulp2 = B2;
        // shift bigB and bigD left by a number s. t.
        // halfUlp is still an integer.
        int hulpbias;
        if (binexp <= -EXP_BIAS) {
            // This is going to be a denormalized number
            // (if not actually zero).
            // half an ULP is at 2^-(DoubleConsts.EXP_BIAS+EXP_SHIFT+1)
            hulpbias = binexp + lowOrderZeros + EXP_BIAS;
        } else {
            hulpbias = 1 + lowOrderZeros;
        }
        B2 += hulpbias;
        D2 += hulpbias;
        // if there are common factors of 2, we might just as well
        // factor them out, as they add nothing useful.
        int common2 = Math.min(B2, Math.min(D2, Ulp2));
        B2 -= common2;
        D2 -= common2;
        Ulp2 -= common2;
        // do multiplications by powers of 5 and 2
        FDBigInteger bigB = FDBigInteger.valueOfMulPow52(bigBbits, B5, B2);
        if (bigD == null || prevD2 != D2) {
            bigD = bigD0.leftShift(D2);
            prevD2 = D2;
        }
        //
        // to recap:
        // bigB is the scaled-big-int version of our floating-point
        // candidate.
        // bigD is the scaled-big-int version of the exact value
        // as we understand it.
        // halfUlp is 1/2 an ulp of bigB, except for special cases
        // of exact powers of 2
        //
        // the plan is to compare bigB with bigD, and if the difference
        // is less than halfUlp, then we're satisfied. Otherwise,
        // use the ratio of difference to halfUlp to calculate a fudge
        // factor to add to the floating value, then go 'round again.
        //
        FDBigInteger diff;
        int cmpResult;
        boolean overvalue;
        if ((cmpResult = bigB.cmp(bigD)) > 0) {
            overvalue = true; // our candidate is too big.
            diff = bigB.leftInplaceSub(bigD); // bigB is not user further - reuse
            if ((bigIntNBits == 1) && (bigIntExp > -EXP_BIAS + 1)) {
                // candidate is a normalized exact power of 2 and
                // is too big (larger than Double.MIN_NORMAL). We will be subtracting.
                // For our purposes, ulp is the ulp of the
                // next smaller range.
                Ulp2 -= 1;
                if (Ulp2 < 0) {
                    // rats. Cannot de-scale ulp this far.
                    // must scale diff in other direction.
                    Ulp2 = 0;
                    diff = diff.leftShift(1);
                }
            }
        } else if (cmpResult < 0) {
            overvalue = false; // our candidate is too small.
            diff = bigD.rightInplaceSub(bigB); // bigB is not user further - reuse
        } else {
            // the candidate is exactly right!
            // this happens with surprising frequency
            break correctionLoop;
        }
        cmpResult = diff.cmpPow52(B5, Ulp2);
        if ((cmpResult) < 0) {
            // difference is small.
            // this is close enough
            break correctionLoop;
        } else if (cmpResult == 0) {
            // difference is exactly half an ULP
            // round to some other value maybe, then finish
            if ((ieeeBits & 1) != 0) { // half ties to even
                ieeeBits += overvalue ? -1 : 1; // nextDown or nextUp
            }
            break correctionLoop;
        } else {
            // difference is non-trivial.
            // could scale addend by ratio of difference to
            // halfUlp here, if we bothered to compute that difference.
            // Most of the time ( I hope ) it is about 1 anyway.
            ieeeBits += overvalue ? -1 : 1; // nextDown or nextUp
            if (ieeeBits == 0 || ieeeBits == EXP_BIT_MASK) { // 0.0 or Double.POSITIVE_INFINITY
                break correctionLoop; // oops. Fell off end of range.
            }
            continue; // try again.
        }

    }
    if (isNegative) {
        ieeeBits |= SIGN_BIT_MASK;
    }
    return Double.longBitsToDouble(ieeeBits);
}

From source file:ffx.algorithms.OSRW.java

/**
 * Send an OSRW count to all other processes while also receiving an OSRW
 * count from all other processes.//from   ww  w  .jav a2s  .  com
 *
 * @param lambda
 * @param dEdU
 */
private void synchronousSend(double lambda, double dEdU) {
    /**
     * All-Gather counts from each walker.
     */
    myRecursionCount[0] = lambda;
    myRecursionCount[1] = dEdU;
    try {
        world.allGather(myRecursionCountBuf, recursionCountsBuf);
    } catch (IOException ex) {
        String message = " Multi-walker OSRW allGather failed.";
        logger.log(Level.SEVERE, message, ex);
    }

    /**
     * Find the minimum and maximum FLambda bin for the gathered counts.
     */
    double minRequired = Double.MAX_VALUE;
    double maxRequired = Double.MIN_VALUE;
    for (int i = 0; i < numProc; i++) {
        minRequired = Math.min(minRequired, recursionCounts[i][1]);
        maxRequired = Math.max(maxRequired, recursionCounts[i][1]);
    }

    /**
     * Check that the FLambda range of the Recursion kernel includes both
     * the minimum and maximum FLambda value.
     */
    checkRecursionKernelSize(minRequired);
    checkRecursionKernelSize(maxRequired);

    /**
     * Increment the Recursion Kernel based on the input of each walker.
     */
    for (int i = 0; i < numProc; i++) {
        int walkerLambda = binForLambda(recursionCounts[i][0]);
        int walkerFLambda = binForFLambda(recursionCounts[i][1]);

        if (resetStatistics && recursionCounts[i][0] > lambdaResetValue) {
            recursionKernel = new int[lambdaBins][FLambdaBins];
            resetStatistics = false;
            logger.info(String.format(" Cleared OSRW histogram (Lambda = %6.4f).", recursionCounts[i][0]));
        }

        recursionKernel[walkerLambda][walkerFLambda]++;
    }
}

From source file:biogenesis.Organism.java

/**
 * Calculates the position of all organism points in the world, depending on
 * its rotation. It also calculates the bounding rectangle of the organism.
 * This method must be called from outside this class only when doing
 * manual drawing.  /*from  ww  w. j av  a  2  s  .co m*/
 * 
 * @param force  To avoid calculations, segments position are only calculated
 * if the organism's rotation has changed in the last frame. If it is necessary
 * to calculate them even when the rotation hasn't changed, assign true to this
 * parameter.
 */
public void calculateBounds(boolean force) {
    double left = java.lang.Double.MAX_VALUE, right = java.lang.Double.MIN_VALUE,
            top = java.lang.Double.MAX_VALUE, bottom = java.lang.Double.MIN_VALUE;

    double theta;
    for (int i = _segments - 1; i >= 0; i--) {
        /* Save calculation: if rotation hasn't changed and it is not forced,
         * don't calculate points again.
         */
        if (_lastTheta != _theta || force) {
            theta = _theta + Math.atan2(_startPointY[i], _startPointX[i]);
            x1[i] = (int) (_m1[i] * Math.cos(theta));
            y1[i] = (int) (_m1[i] * Math.sin(theta));
            theta = _theta + Math.atan2(_endPointY[i], _endPointX[i]);
            x2[i] = (int) (_m2[i] * Math.cos(theta));
            y2[i] = (int) (_m2[i] * Math.sin(theta));
        }
        // Finds the rectangle that comprises the organism
        left = Utils.min(left, x1[i] + _dCenterX, x2[i] + _dCenterX);
        right = Utils.max(right, x1[i] + _dCenterX, x2[i] + _dCenterX);
        top = Utils.min(top, y1[i] + _dCenterY, y2[i] + _dCenterY);
        bottom = Utils.max(bottom, y1[i] + _dCenterY, y2[i] + _dCenterY);
    }
    setBounds((int) left, (int) top, (int) (right - left + 1) + 1, (int) (bottom - top + 1) + 1);
    _lastTheta = _theta;
}

From source file:main.java.biogenesis.Organism.java

/**
 * Calculates the position of all organism points in the world, depending on
 * its rotation. It also calculates the bounding rectangle of the organism.
 * This method must be called from outside this class only when doing
 * manual drawing.  /* w  w  w. j  av a 2s.  c o m*/
 * 
 * @param force  To avoid calculations, segments position are only calculated
 * if the organism's rotation has changed in the last frame. If it is necessary
 * to calculate them even when the rotation hasn't changed, assign true to this
 * parameter.
 */
public void calculateBounds(boolean force) {
    double left = java.lang.Double.MAX_VALUE, right = java.lang.Double.MIN_VALUE,
            top = java.lang.Double.MAX_VALUE, bottom = java.lang.Double.MIN_VALUE;

    double theta;
    for (int i = _segments - 1; i >= 0; i--) {
        /* Save calculation: if rotation hasn't changed and it is not forced,
         * don't calculate points again.
         */
        if ((Math.abs(_lastTheta - _theta) > 0.00001) || force) {
            theta = _theta + Math.atan2(_startPointY[i], _startPointX[i]);
            x1[i] = (int) (_m1[i] * Math.cos(theta));
            y1[i] = (int) (_m1[i] * Math.sin(theta));
            theta = _theta + Math.atan2(_endPointY[i], _endPointX[i]);
            x2[i] = (int) (_m2[i] * Math.cos(theta));
            y2[i] = (int) (_m2[i] * Math.sin(theta));
        }
        // Finds the rectangle that comprises the organism
        left = Utils.min(left, x1[i] + _dCenterX, x2[i] + _dCenterX);
        right = Utils.max(right, x1[i] + _dCenterX, x2[i] + _dCenterX);
        top = Utils.min(top, y1[i] + _dCenterY, y2[i] + _dCenterY);
        bottom = Utils.max(bottom, y1[i] + _dCenterY, y2[i] + _dCenterY);
    }
    setBounds((int) left, (int) top, (int) (right - left + 1) + 1, (int) (bottom - top + 1) + 1);
    _lastTheta = _theta;
}

From source file:com.jjoe64.graphview.Viewport.java

/**
 * caches the complete range (minX, maxX, minY, maxY)
 * by iterating all series and all datapoints and
 * stores it into #mCompleteRange//from  w  w  w.ja  va 2 s . co m
 *
 * for the x-range it will respect the series on the
 * second scale - not for y-values
 */
public void calcCompleteRange() {
    List<Series> series = mGraphView.getSeries();
    List<Series> seriesInclusiveSecondScale = new ArrayList<>(mGraphView.getSeries());
    if (mGraphView.mSecondScale != null) {
        seriesInclusiveSecondScale.addAll(mGraphView.mSecondScale.getSeries());
    }
    mCompleteRange.set(0d, 0d, 0d, 0d);
    if (!seriesInclusiveSecondScale.isEmpty() && !seriesInclusiveSecondScale.get(0).isEmpty()) {
        double d = seriesInclusiveSecondScale.get(0).getLowestValueX();
        for (Series s : seriesInclusiveSecondScale) {
            if (!s.isEmpty() && d > s.getLowestValueX()) {
                d = s.getLowestValueX();
            }
        }
        mCompleteRange.left = d;

        d = seriesInclusiveSecondScale.get(0).getHighestValueX();
        for (Series s : seriesInclusiveSecondScale) {
            if (!s.isEmpty() && d < s.getHighestValueX()) {
                d = s.getHighestValueX();
            }
        }
        mCompleteRange.right = d;

        if (!series.isEmpty() && !series.get(0).isEmpty()) {
            d = series.get(0).getLowestValueY();
            for (Series s : series) {
                if (!s.isEmpty() && d > s.getLowestValueY()) {
                    d = s.getLowestValueY();
                }
            }
            mCompleteRange.bottom = d;

            d = series.get(0).getHighestValueY();
            for (Series s : series) {
                if (!s.isEmpty() && d < s.getHighestValueY()) {
                    d = s.getHighestValueY();
                }
            }
            mCompleteRange.top = d;
        }
    }

    // calc current viewport bounds
    if (mYAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
        mYAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    }
    if (mYAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
        mCurrentViewport.top = mCompleteRange.top;
        mCurrentViewport.bottom = mCompleteRange.bottom;
    }

    if (mXAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
        mXAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    }
    if (mXAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
        mCurrentViewport.left = mCompleteRange.left;
        mCurrentViewport.right = mCompleteRange.right;
    } else if (mXAxisBoundsManual && !mYAxisBoundsManual && mCompleteRange.width() != 0) {
        // get highest/lowest of current viewport
        // lowest
        double d = Double.MAX_VALUE;
        for (Series s : series) {
            if (mYAxisBoundsAutoOverCompleteData) {
                double v = s.getLowestValueY();
                if (d > v) {
                    d = v;
                }
            } else {
                Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left,
                        mCurrentViewport.right);
                while (values.hasNext()) {
                    double v = values.next().getY();
                    if (d > v) {
                        d = v;
                    }
                }
            }
        }

        if (d != Double.MAX_VALUE) {
            mCurrentViewport.bottom = d;
        }

        // highest
        d = Double.MIN_VALUE;
        for (Series s : series) {
            if (mYAxisBoundsAutoOverCompleteData) {
                double v = s.getHighestValueY();
                if (d > v) {
                    d = v;
                }
            } else {
                Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left,
                        mCurrentViewport.right);
                while (values.hasNext()) {
                    double v = values.next().getY();
                    if (d < v) {
                        d = v;
                    }
                }
            }
        }

        if (d != Double.MIN_VALUE) {
            mCurrentViewport.top = d;
        }
    }

    // fixes blank screen when range is zero
    if (mCurrentViewport.left == mCurrentViewport.right)
        mCurrentViewport.right++;
    if (mCurrentViewport.top == mCurrentViewport.bottom)
        mCurrentViewport.top++;
}

From source file:p5e610.graphview.Viewport.java

/**
 * caches the complete range (minX, maxX, minY, maxY)
 * by iterating all series and all datapoints and
 * stores it into #mCompleteRange/*from  ww  w . j  ava 2 s  .  c  o  m*/
 *
 * for the x-range it will respect the series on the
 * second scale - not for y-values
 *
 */
public void calcCompleteRange() {
    List<Series> series = mGraphView.getSeries();
    List<Series> seriesInclusiveSecondScale = new ArrayList<>(mGraphView.getSeries());
    if (mGraphView.mSecondScale != null) {
        seriesInclusiveSecondScale.addAll(mGraphView.mSecondScale.getSeries());
    }
    mCompleteRange.set(0d, 0d, 0d, 0d);
    if (!seriesInclusiveSecondScale.isEmpty() && !seriesInclusiveSecondScale.get(0).isEmpty()) {
        double d = seriesInclusiveSecondScale.get(0).getLowestValueX();
        for (Series s : seriesInclusiveSecondScale) {
            if (!s.isEmpty() && d > s.getLowestValueX()) {
                d = s.getLowestValueX();
            }
        }
        mCompleteRange.left = d;

        d = seriesInclusiveSecondScale.get(0).getHighestValueX();
        for (Series s : seriesInclusiveSecondScale) {
            if (!s.isEmpty() && d < s.getHighestValueX()) {
                d = s.getHighestValueX();
            }
        }
        mCompleteRange.right = d;

        if (!series.isEmpty() && !series.get(0).isEmpty()) {
            d = series.get(0).getLowestValueY();
            for (Series s : series) {
                if (!s.isEmpty() && d > s.getLowestValueY()) {
                    d = s.getLowestValueY();
                }
            }
            mCompleteRange.bottom = d;

            d = series.get(0).getHighestValueY();
            for (Series s : series) {
                if (!s.isEmpty() && d < s.getHighestValueY()) {
                    d = s.getHighestValueY();
                }
            }
            mCompleteRange.top = d;
        }
    }

    // calc current viewport bounds
    if (mYAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
        mYAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    }
    if (mYAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
        mCurrentViewport.top = mCompleteRange.top;
        mCurrentViewport.bottom = mCompleteRange.bottom;
    }

    if (mXAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
        mXAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    }
    if (mXAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
        mCurrentViewport.left = mCompleteRange.left;
        mCurrentViewport.right = mCompleteRange.right;
    } else if (mXAxisBoundsManual && !mYAxisBoundsManual && mCompleteRange.width() != 0) {
        // get highest/lowest of current viewport
        // lowest
        double d = Double.MAX_VALUE;
        for (Series s : series) {
            Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left, mCurrentViewport.right);
            while (values.hasNext()) {
                double v = values.next().getY();
                if (d > v) {
                    d = v;
                }
            }
        }

        if (d != Double.MAX_VALUE) {
            mCurrentViewport.bottom = d;
        }

        // highest
        d = Double.MIN_VALUE;
        for (Series s : series) {
            Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left, mCurrentViewport.right);
            while (values.hasNext()) {
                double v = values.next().getY();
                if (d < v) {
                    d = v;
                }
            }
        }

        if (d != Double.MIN_VALUE) {
            mCurrentViewport.top = d;
        }
    }

    // fixes blank screen when range is zero
    if (mCurrentViewport.left == mCurrentViewport.right)
        mCurrentViewport.right++;
    if (mCurrentViewport.top == mCurrentViewport.bottom)
        mCurrentViewport.top++;

    // if we have a minimum size
    if (!Double.isNaN(mAllowedSize)) {
        mCompleteRange.left = Math.min(mCompleteRange.left, mCompleteRange.right - mAllowedSize);
    }
}

From source file:org.odk.collect.android.activities.GeoTraceOsmMapActivity.java

private void zoomToBounds() {
    mapView.getController().setZoom(4);/*from w  w  w  .  j a v  a2  s .c o  m*/
    mapView.invalidate();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            double minLat = Double.MAX_VALUE;
            double maxLat = Double.MIN_VALUE;
            double minLong = Double.MAX_VALUE;
            double maxLong = Double.MIN_VALUE;
            Integer size = mapMarkers.size();
            for (int i = 0; i < size; i++) {
                GeoPoint tempMarker = mapMarkers.get(i).getPosition();
                if (tempMarker.getLatitude() < minLat) {
                    minLat = tempMarker.getLatitude();
                }
                if (tempMarker.getLatitude() > maxLat) {
                    maxLat = tempMarker.getLatitude();
                }
                if (tempMarker.getLongitude() < minLong) {
                    minLong = tempMarker.getLongitude();
                }
                if (tempMarker.getLongitude() > maxLong) {
                    maxLong = tempMarker.getLongitude();
                }
            }
            BoundingBox boundingBox = new BoundingBox(maxLat, maxLong, minLat, minLong);
            mapView.zoomToBoundingBox(boundingBox, false);
            mapView.invalidate();
        }
    }, 100);
    mapView.invalidate();

}

From source file:com.cfelde.aws.ddb.management.TableThroughput.java

/**
 * Returns number of consumed write per second.
 *
 * @return Reads per second/*www.j  a  v  a2 s . co m*/
 */
public double getConsumedWriteCapacity() {
    synchronized (lock) {
        GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
        request.setStatistics(Collections.singleton("Sum"));
        request.setDimensions(Arrays.asList(new Dimension().withName("TableName").withValue(tableName)));
        request.setNamespace("AWS/DynamoDB");
        request.setStartTime(new Date(System.currentTimeMillis() - (1000L * period * 5)));
        request.setEndTime(new Date(System.currentTimeMillis() + 60000L));
        request.setPeriod(period);
        request.setMetricName("ConsumedWriteCapacityUnits");

        GetMetricStatisticsResult result = client.getMetricStatistics(request);

        if (!result.getDatapoints().isEmpty()) {
            List<Datapoint> dataPoints = new ArrayList<>(result.getDatapoints());

            Collections.sort(dataPoints, new Comparator<Datapoint>() {
                @Override
                public int compare(Datapoint o1, Datapoint o2) {
                    return o2.getTimestamp().compareTo(o1.getTimestamp());
                }
            });

            Datapoint datapoint = dataPoints.get(0);

            consumedWriteValues.add(datapoint.getSum() / period);
        } else {
            consumedWriteValues.add(0D);
        }

        while (consumedWriteValues.size() > maxConsumedCount)
            consumedWriteValues.remove(0);

        if (consumedWriteValues.isEmpty())
            return 0;

        double maxConsumedValue = Double.MIN_VALUE;
        for (Double c : consumedWriteValues) {
            if (c > maxConsumedValue)
                maxConsumedValue = c;
        }

        return maxConsumedValue;
    }
}

From source file:uk.ac.leeds.ccg.andyt.generic.visualisation.charts.Generic_ScatterPlotAndLinearRegression.java

/**
 *
 * @param data/*  w ww. jav a 2s.  co m*/
 * @param lineParameters
 * @return
 */
public static double[][] getXYLineData(double[][] data, double[] lineParameters) {
    double[][] result = new double[2][2];
    double miny = Double.MAX_VALUE;
    double maxy = Double.MIN_VALUE;
    double minx = Double.MAX_VALUE;
    double maxx = Double.MIN_VALUE;
    for (int j = 0; j < data[0].length; j++) {
        minx = Math.min(minx, data[0][j]);
        maxx = Math.max(maxx, data[0][j]);
        miny = Math.min(miny, data[1][j]);
        maxy = Math.max(maxy, data[1][j]);
    }
    result[0][0] = minx;
    result[0][1] = maxx;
    result[1][0] = miny;
    result[1][1] = maxy;
    //        System.out.println("miny " + minx);
    //        System.out.println("maxy " + maxx);
    //        System.out.println("minx " + miny);
    //        System.out.println("maxx " + maxy);
    double m = lineParameters[1];
    double c = lineParameters[0];
    // y = (m * x) + c
    // x = (y - c) / m
    // minyx stores the y at minx
    double minyx;
    // maxyx stores the y at maxx 
    double maxyx;
    if (m != 0) {
        minyx = (minx - c) / m;
        maxyx = (maxx - c) / m;
    } else {
        minyx = miny;
        maxyx = maxy;
    }
    // minxy stores the x at miny
    double minxy = (m * miny) + c;
    // maxxy stores the x at maxy
    double maxxy = (m * maxy) + c;

    if (maxxy < maxx) {
        result[0][1] = maxxy;
    } else {
        result[1][1] = maxyx;
    }
    if (minxy > minx) {
        result[0][0] = minxy;
    } else {
        result[1][0] = minyx;
    }

    if (maxyx < maxy) {
        result[1][1] = maxyx;
    } else {
        result[0][1] = maxxy;
    }

    if (minyx > miny) {
        result[1][0] = minyx;
    } else {
        result[0][0] = minxy;
    }

    if (Double.isNaN(result[1][0])) {
        if (Double.isNaN(result[0][0])) {
            result[1][0] = 0;
            result[0][0] = 0;
        } else {
            result[1][0] = result[0][0];
            //result[1][0] = 0;
        }
    }
    if (Double.isNaN(result[1][1])) {
        if (Double.isNaN(result[0][1])) {
            result[1][1] = 0;
            result[0][1] = 0;
        } else {
            result[1][1] = result[0][1];
            //result[1][1] = 0;
        }
    }

    System.out.println("Line Segment");
    System.out.println("(minx,miny) (" + result[1][0] + "," + result[0][0] + ")");
    System.out.println("(maxx,maxy) (" + result[1][1] + "," + result[0][1] + ")");
    return result;
}