import java.util.Arrays;
/**
* Static methods for doing useful math
*
* @author : $Author: brian $
* @version : $Revision: 1.1 $
*
*
* The Monterey Bay Aquarium Research Institute (MBARI) provides this
* documentation and code "as is", with no warranty, express or
* implied, of its quality or consistency. It is provided without support and
* without obligation on the part of MBARI to assist in its use, correction,
* modification, or enhancement. This information should not be published or
* distributed to third parties without specific written permission from
* MBARI.
*
* Copyright 2002 MBARI.
* MBARI Proprietary Information. All rights reserved.
*
*/
public class Util{
/**
* Retrive the quartile value from an array
* .
* @param values THe array of data
* @param lowerPercent The percent cut off. For the lower quartile use 25,
* for the upper-quartile use 75
* @return
*/
public static double quartile(double[] values, double lowerPercent) {
if (values == null || values.length == 0) {
throw new IllegalArgumentException("The data array either is null or does not contain any data.");
}
// Rank order the values
double[] v = new double[values.length];
System.arraycopy(values, 0, v, 0, values.length);
Arrays.sort(v);
int n = (int) Math.round(v.length * lowerPercent / 100);
return v[n];
}
}