private int[] recalculateColSizesForScreen(int screenWidth, int[] colSizes,
      String colSeparators) {
    if (!screen.shouldTrimColumns()) {
      // Returning original colSizes since reader is set to external
      return colSizes;
    }

    // change the screen width to account for separator chars
    screenWidth -= (colSizes.length - 1) * colSeparators.length();

    // build sorted list and find total width
    List<ComparableColumn> stringList = new ArrayList<>();
    int index = 0;
    int totalLength = 0;
    for (int k : colSizes) {
      ComparableColumn cs = new ComparableColumn();
      cs.originalIndex = index++;
      cs.length = k;
      stringList.add(cs);
      totalLength += k;
    }

    // No need to reduce the column width return orig array
    if (totalLength <= screenWidth) {
      return colSizes;
    }

    Collections.sort(stringList);

    // find out columns which need trimming
    totalLength = 0;
    int spaceLeft = 0;
    int totalExtra = 0;
    for (ComparableColumn s : stringList) {
      int newLength = totalLength + s.length;
      // Ensure that the spaceLeft is never < 2 which would prevent displaying a trimmed value
      // even when there is space available on the screen.
      if (newLength + SCREEN_WIDTH_MARGIN_BUFFER > screenWidth) {
        s.markForTrim = true;
        totalExtra += s.length;
        if (spaceLeft == 0) {
          spaceLeft = screenWidth - totalLength;
        }
      }
      totalLength = newLength;
    }

    stringList.sort(Comparator.comparingInt(o -> o.originalIndex));

    // calculate trimmed width for columns marked for
    // distribute the trimming as per percentage
    int[] finalColSizes = new int[colSizes.length];
    int i = 0;
    for (ComparableColumn s : stringList) {
      if (totalLength > screenWidth) {
        if (s.markForTrim) {
          s.trimmedLength = (int) Math.floor(spaceLeft * ((double) s.length / totalExtra));
        } else {
          s.trimmedLength = s.length;
        }
      } else {
        s.trimmedLength = s.length;
      }
      finalColSizes[i] = s.trimmedLength;
      i++;
    }

    totalLength = 0;
    index = 0;
    for (int colSize : finalColSizes) {
      if (colSize != colSizes[index] && colSize < 2) {
        throw new TooManyColumnsException("Computed ColSize=" + colSize
            + " Set RESULT_VIEWER to external. This uses the 'less' command (with horizontal scrolling) to see wider results");
      }
      totalLength += colSize;
      index++;
    }
    return finalColSizes;
  }
A group of rows. Widths for all columns within a group will be the same and when built will
automatically be set to the length of the longest value in the column.

@since GemFire 7.0
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/result/RowGroup.java