1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import java.util.ArrayList;
import java.util.DoubleSummaryStatistics;
import java.util.List;
/**
*
*/
/**
* @author Warnotte Renaud
*/
public class Averager
{
/**
* @param args
*/
public static void main(String[] args)
{
List<DTO> list = new ArrayList<>();
list.add(new DTO(1960, 1, Double.NaN));
list.add(new DTO(1960, 2, 23.67));
list.add(new DTO(1960, 3, 21.56));
list.add(new DTO(1960, 4, 7.25));
list.add(new DTO(1961, 1, 37.99));
list.add(new DTO(1961, 2, 5.87));
list.add(new DTO(1961, 3, 9.23));
list.add(new DTO(1983, 1, 23.10));
list.add(new DTO(1983, 2, 34.21));
list.add(new DTO(1983, 3, 10.14));
list.add(new DTO(1999, 1, 12.13));
list.add(new DTO(1999, 2, 25.43));
list.add(new DTO(1999, 3, 17.80));
list.add(new DTO(1999, 4, 22.23));
list.add(new DTO(2000, 1, 10.59));
list.add(new DTO(2000, 2, 14.65));
list.add(new DTO(2000, 3, 29.13));
list.add(new DTO(2001, 1, 15.17));
list.add(new DTO(2001, 2, 8.25));
list.add(new DTO(2001, 3, Double.NaN));
list.add(new DTO(2001, 4, Double.NaN));
DoubleSummaryStatistics statistics = list.stream()
.filter(e -> e.getMois()==2) // Filtre par mois
.mapToDouble(DTO::getTMao) // Statistique sur TMao
.summaryStatistics();
double Average = statistics.getAverage();
System.out.println("Avg = "+Average);
}
} |
Partager