PriceSpliter { private ImmutablePair<BigDecimal, BigDecimal> calcConfidenceSection(double avg, double sd){ if(Double.isNaN(avg) || Double.isNaN(sd)){ throw new IllegalArgumentException("avg or sd is not a number: "+avg+", "+sd); } Double zscore = ConfidenceLevelUtils.getZscore(95); return ConfidenceLevelUtils.calcConfidenceSection(BigDecimal.valueOf(avg), BigDecimal.valueOf(sd), zscore); } PriceSpliter(double averagePrice, double stdDeviation, long totalCount, int expectSectionSize); static List<ImmutablePair<Integer, Integer>> split(ImmutablePair<BigDecimal, BigDecimal> section, int maxSplitCount); List<RangeQueryer> getRangeQueryers(); List<String> splitAndGetKeys(List<RangeResult> rangeResult); List<RangeResult> split(List<RangeResult> rangeResult); long getTotalCount();  }
@Test public void testCalcConfidenceSection(){ int maxCount = 32; ImmutablePair<BigDecimal, BigDecimal> section = ConfidenceLevelUtils.calcConfidenceSection(57.27, 171.67); System.out.println("sections:"+section); final List<ImmutablePair<Integer, Integer>> splits = PriceSpliter.split(section, maxCount); System.out.println("splits["+splits.size()+"]:"+splits); AtomicInteger index = new AtomicInteger(0); List<RangeResult> rangeResult = splits.stream().map(pair->{ RangeResult r = new RangeResult(pair.getLeft(), pair.getRight()); if(index.get()==1){ r.setDocCount(1); }else if(index.get()==2){ r.setDocCount(2); }else if(index.get()==5){ r.setDocCount(7); }else if(index.get()==8){ r.setDocCount(4); }else if(index.get()==splits.size()){ r.setDocCount(5); } index.incrementAndGet(); return r; }) .collect(Collectors.toList()); System.out.println("splits["+rangeResult.size()+"]:"+rangeResult); double stdDeviation = 57; PriceSpliter spliter = new PriceSpliter(57, stdDeviation, rangeResult.size(), 5); List<RangeResult> mereged = spliter.split(rangeResult); System.out.println("mereged["+mereged.size()+"]:"+mereged); List<ImmutablePair<Integer, Integer>> splits2 = PriceSpliter.split(ImmutablePair.of(BigDecimal.valueOf(0), BigDecimal.valueOf(1000000)), maxCount); System.out.println("splits["+splits2.size()+"]:"+splits2); }