void (final boolean[] higherPriorityCells, final DimensionInfo info, int toDistribute, final int[] widths) { int stretches = 0; for (int i = 0; i < info.getCellCount(); i++) { if (higherPriorityCells[i]) { stretches += info.getStretch(i); } } { final int toDistributeFrozen = toDistribute; for (int i = 0; i < info.getCellCount(); i++) { if (!higherPriorityCells[i]) { continue; } final int addon = toDistributeFrozen * info.getStretch(i) / stretches; widths[i] += addon; toDistribute -= addon; } } if (toDistribute != 0) { for (int i = 0; i < info.getCellCount(); i++) { if (!higherPriorityCells[i]) { continue; } widths[i]++; toDistribute--; if (toDistribute == 0) { break; } } } if (toDistribute != 0) { throw new IllegalStateException("toDistribute = " + toDistribute); } }