Here you can find the source of getRange(List
Parameter | Description |
---|---|
numbers | the input list |
public static double getRange(List<Double> numbers)
//package com.java2s; /*/*w w w. j a v a2 s. c o m*/ * File : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.survey/src/com/alkacon/opencms/survey/CmsAverageUtil.java,v $ * Date : $Date: 2010/03/19 15:31:14 $ * Version: $Revision: 1.2 $ * * This library is part of OpenCms - * the Open Source Content Management System * * Copyright (C) 2010 Alkacon Software (http://www.alkacon.com) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * For further information about Alkacon Software, please see the * company website: http://www.alkacon.com * * For further information about OpenCms, please see the * project website: http://www.opencms.org * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.List; public class Main { /** * Returns the difference between the maximum and the minimum of a list of Doubles.<p> * * @param numbers the input list * @return the range of the input list */ public static double getRange(List<Double> numbers) { return getMax(numbers) - getMin(numbers); } /** * Finds the maximum from a list of Doubles.<p> * * If the list is empty, 0 is returned. * * @param numbers the list of Doubles * @return the maximum */ public static double getMax(List<Double> numbers) { if (numbers.size() == 0) { return 0.0; } double max = numbers.get(0); for (Double number : numbers) { max = Math.max(max, number); } return max; } /** * Finds the minimum from a list of Doubles.<p> * * If the list is empty, 0 is returned. * @param numbers the list of Doubles * @return the minimum */ public static double getMin(List<Double> numbers) { if (numbers.size() == 0) { return 0.0; } double min = numbers.get(0); for (Double number : numbers) { min = Math.min(min, number); } return min; } }