四分位数计算

            int size = overDays.size();
            if (size == 1){
                midDay = BigDecimal.valueOf(overDays.get(0));
                minDay = BigDecimal.valueOf(overDays.get(0));
                maxDay = BigDecimal.valueOf(overDays.get(0));
            }else if (size == 2){
                midDay = BigDecimal.valueOf((overDays.get(0)+overDays.get(1)+0.0)/2);
                minDay = BigDecimal.valueOf(overDays.get(0));
                maxDay = BigDecimal.valueOf(overDays.get(1));
            }else if (size == 3){
                midDay = BigDecimal.valueOf(overDays.get(1));
                minDay = BigDecimal.valueOf(overDays.get(0));
                maxDay = BigDecimal.valueOf(overDays.get(2));
            }else {
                if (size % 2 == 1){ //奇数
                    midDay = BigDecimal.valueOf(overDays.get((size - 1) / 2));
                    int i = (size - 1) / 2;
                    if (i % 2 == 1){ //奇数
                        minDay = BigDecimal.valueOf(overDays.get((i-1)/2));
                        maxDay = BigDecimal.valueOf(overDays.get((3*size-1)/4));
                    }else { //偶数
                        minDay = BigDecimal.valueOf((overDays.get(i-i/2)+overDays.get(i-i/2-1)+0.0)/2);
                        maxDay = BigDecimal.valueOf((overDays.get(i+i/2)+overDays.get(i+i/2+1)+0.0)/2);
                    }
                }else { //偶数
                    midDay = BigDecimal.valueOf((overDays.get(size/2-1)+overDays.get(size/2)+0.0)/2);
                    int i = (size - 1) / 2;
                    if (i % 2 == 1){ //奇数
                        minDay = BigDecimal.valueOf((size-2)/4);
                        maxDay = BigDecimal.valueOf(overDays.get((size*3-2)/4));
                    }else { //偶数
                        minDay = BigDecimal.valueOf((overDays.get(size/4-1)+overDays.get(size/4)+0.0)/2);
                        maxDay = BigDecimal.valueOf((overDays.get(3*size/4-1)+overDays.get(3*size/4)+0.0)/2);
                    }
                }
            }

 

你可能感兴趣的:(基础篇)