Java Array Min Value minMaxOverArraySubset(double[] array, Iterable subset, boolean min)

Here you can find the source of minMaxOverArraySubset(double[] array, Iterable subset, boolean min)

Description

Compute the minimum or maximum value over a subset of an array of doubles.

License

Open Source License

Parameter

Parameter Description
array The array
subset The subset
min Min or max (true = min, false = max)

Declaration

public static double minMaxOverArraySubset(double[] array,
        Iterable<Integer> subset, boolean min) 

Method Source Code

//package com.java2s;
//   it under the terms of the GNU General Public License as published by

public class Main {
    /**//w w w .  j  av a 2s  .  c  o  m
     * Compute the minimum or maximum value over a subset of an array of doubles.
     * @param array The array
     * @param subset The subset
     * @param min Min or max (true = min, false = max) 
     */
    public static double minMaxOverArraySubset(double[] array,
            Iterable<Integer> subset, boolean min) {
        if (min)
            return minOverArraySubset(array, subset);
        else
            return maxOverArraySubset(array, subset);
    }

    /**
     * Compute the minimum value over a subset of an array of doubles.
     * @param array The array
     * @param subset The subset
     */
    public static double minOverArraySubset(double[] array,
            Iterable<Integer> subset) {
        double d;
        d = Double.POSITIVE_INFINITY;
        for (int j : subset) {
            if (array[j] < d)
                d = array[j];
        }
        return d;
    }

    /**
     * Compute the maximum value over a subset of an array of doubles.
     * @param array The array
     * @param subset The subset
     */
    public static double maxOverArraySubset(double[] array,
            Iterable<Integer> subset) {
        double d;
        d = Double.NEGATIVE_INFINITY;
        for (int j : subset) {
            if (array[j] > d)
                d = array[j];
        }
        return d;
    }
}

Related

  1. minMax(float[] array)
  2. minmax(int[] values)
  3. minMax(int[] values)
  4. minmax(String args[], boolean minimum)
  5. minMaxAvg(int[] arr)
  6. minNonNeg(int... vals)
  7. minNum(Number iArr[])
  8. minOf(double[] da, double val)
  9. minOfArr(int[] arrInput)