### Question:
HistogramIntegrator { public IntegratedHistogram integrate(FullCrossMarketOpportunity.Histogram[] histogram, int priceScale, int amountScale, boolean isMarketSell) { if (0 == histogram.length) { throw new IllegalStateException("Empty histogram"); } double min = minPrice(histogram); double max = maxPrice(histogram); double origStep = (max - min) / histogram.length; double[] inOrder = new double[histogram.length]; for (FullCrossMarketOpportunity.Histogram entry : histogram) { int pos = (int) (((entry.getMinPrice() + entry.getMaxPrice()) / 2.0 - min) / origStep); inOrder[pos] = Math.abs(entry.getAmount()); } long[] asLong = new long[histogram.length]; long step = RoundingUtil.longVal(BigDecimal.valueOf(origStep), priceScale, RoundingMode.CEILING); BigDecimal summ = BigDecimal.ZERO; int start = isMarketSell ? 0 : histogram.length - 1; int end = isMarketSell ? histogram.length : 0; int iStep = isMarketSell ? 1 : -1; for (int i = start; isMarketSell ? i < end : i >= 0; i += iStep) { summ = summ.add(BigDecimal.valueOf(inOrder[i])); asLong[isMarketSell ? i : start - i] = RoundingUtil.longVal(summ, amountScale, RoundingMode.FLOOR); } long minLong = RoundingUtil.longVal(BigDecimal.valueOf(min), priceScale, RoundingMode.FLOOR); long maxLong = minLong + step * histogram.length; return new IntegratedHistogram(step, minLong, maxLong, !isMarketSell, priceScale, asLong); }  IntegratedHistogram integrate(FullCrossMarketOpportunity.Histogram[] histogram, int priceScale,
                                         int amountScale, boolean isMarketSell);  }### Answer:
@Test public void integrateSell0Scale() { IntegratedHistogram res = integrator.integrate(sell, 0, 0, true); assertThat(res.getAmount()).containsExactly(5, 5, 15, 23); assertThat(res.getMinPrice()).isEqualTo(10); assertThat(res.getMaxPrice()).isEqualTo(30); assertThat(res.amount(9)).isEqualTo(0); assertThat(res.amount(10)).isEqualTo(0); assertThat(res.amount(11)).isEqualTo(1); assertThat(res.amount(16)).isEqualTo(5); assertThat(res.amount(24)).isEqualTo(13); assertThat(res.amount(25)).isEqualTo(15); assertThat(res.amount(30)).isEqualTo(23); assertThat(res.amount(35)).isEqualTo(23); }
@Test public void integrateBuy0Scale() { IntegratedHistogram res = integrator.integrate(buy, 0, 0, false); assertThat(res.getAmount()).containsExactly(3, 8, 8); assertThat(res.getMinPrice()).isEqualTo(4); assertThat(res.getMaxPrice()).isEqualTo(10); assertThat(res.amount(11)).isEqualTo(0); assertThat(res.amount(10)).isEqualTo(0); assertThat(res.amount(9)).isEqualTo(1); assertThat(res.amount(8)).isEqualTo(3); assertThat(res.amount(7)).isEqualTo(5); assertThat(res.amount(6)).isEqualTo(8); assertThat(res.amount(4)).isEqualTo(8); assertThat(res.amount(2)).isEqualTo(8); }