Dimension (final Container container) { validateInfos(container); // IMPORTANT!!! DO NOT INLINE!!! final DimensionInfo horizontalInfo = myHorizontalInfo; final DimensionInfo verticalInfo = myVerticalInfo; final Dimension result = getTotalGap(container, horizontalInfo, verticalInfo); final int[] widths = getPrefSizes(horizontalInfo); if (mySameSizeHorizontally) { makeSameSizes(widths); } result.width += sum(widths); final int[] heights = getPrefSizes(verticalInfo); if (mySameSizeVertically) { makeSameSizes(heights); } result.height += sum(heights); return result; }