Java List Min getMinimums(List data)

Here you can find the source of getMinimums(List data)

Description

get Minimums

License

Apache License

Declaration

public static List<Double> getMinimums(List<Double> data) 

Method Source Code

//package com.java2s;
/**************************************************************************************
Copyright 2015 Applied Research Associates, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the License
at:/* w ww  .j ava2s . com*/
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
**************************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Double> getMinimums(List<Double> data) {
        List<Double> xMin = new ArrayList<Double>();
        List<Double> yMin = new ArrayList<Double>();
        List<Double> xMax = new ArrayList<Double>();
        List<Double> yMax = new ArrayList<Double>();
        getPeriodBounds(data, data, xMin, yMin, xMax, yMax);
        return xMin;
    }

    public static void getPeriodBounds(List<Double> xData, List<Double> yData, List<Double> xMin, List<Double> yMin,
            List<Double> xMax, List<Double> yMax) {
        if (xData.size() != yData.size())
            throw new RuntimeException("Waveform x and y data not the same size");

        xMin.clear();
        yMin.clear();
        xMax.clear();
        yMax.clear();

        // Ride the y value, and save off the min/max when we hit one, and the x value at those points
        double p1, p2;
        Boolean looking4max = null;
        for (int i = 1; i < yData.size(); i++) {
            p1 = yData.get(i - 1);
            p2 = yData.get(i);
            if (p1 == p2)
                continue;
            if (p2 > p1) {
                looking4max = true;
                break;
            }
            if (p1 > p2) {
                looking4max = false;
                break;
            }
        }
        if (looking4max != null) {
            for (int i = 1; i < yData.size(); i++) {
                p1 = yData.get(i - 1);
                p2 = yData.get(i);
                if (p1 == p2)
                    continue;
                if (looking4max && p2 < p1) {
                    looking4max = false;
                    xMax.add(xData.get(i - 1));
                    yMax.add(p1);
                }
                if (!looking4max && p2 > p1) {
                    looking4max = true;
                    xMin.add(xData.get(i - 1));
                    yMin.add(p1);
                }
            }
        } else// All the values are the same!
        {
            yMin.add(yData.get(0));
            yMax.add(yData.get(0));
            xMin.add(xData.get(0));
            xMax.add(xData.get(0));
        }
    }
}

Related

  1. getMin(List numList)
  2. getMin(List aList)
  3. getMin(List d)
  4. getMin(List numbers)
  5. getMinId(List ids)
  6. getMinValue(List values)
  7. getMinWhitespace(final List lines)
  8. min(final List aList, final Double aDefalut)
  9. min(List values)