private int renderOptions(StringBuilder sb, Collection<Option> options) {
        String lpad = OptionUtils.createPadding(getLeftPad());
        String dpad = OptionUtils.createPadding(getDescPad());

        // first create list containing only <lpad>-a,--aaa where 
        // -a is opt and --aaa is long opt; in parallel look for 
        // the longest opt string this list will be then used to 
        // sort options ascending
        int leftWidth = 0;
        List<StringBuilder> lineBufList = new ArrayList<>();
        Collection<Option> optList = options;
        if (optList.size() > 1 && getOptionComparator() != null) {
            List<Option> optList2 = new ArrayList<>(optList);
            optList2.sort(getOptionComparator());
            optList = optList2;
        }
        for (Option option : optList) {
            StringBuilder lineBuf = new StringBuilder();
            if (option.getName() == null) {
                lineBuf.append(lpad).append(LONG_OPTION_PREFIX).append(option.getLongName());
            } else {
                lineBuf.append(lpad).append(OPTION_PREFIX).append(option.getName());
                if (option.hasLongName()) {
                    lineBuf.append(", ").append(LONG_OPTION_PREFIX).append(option.getLongName());
                }
            }
            if (option.hasValue()) {
                String argName = option.getValueName();
                if (argName != null && argName.isEmpty()) {
                    // if the option has a blank arg name
                    lineBuf.append(' ');
                } else {
                    lineBuf.append(option.isWithEqualSign() ? '=' : LONG_OPTION_SEPARATOR);
                    lineBuf.append(ARG_BRACKET_OPEN).append(argName != null ? argName : getArgName()).append(ARG_BRACKET_CLOSE);
                }
            }
            lineBufList.add(lineBuf);
            leftWidth = (lineBuf.length() > leftWidth ? lineBuf.length() : leftWidth);
        }

        if (leftWidth > getMaxLeftWidth()) {
            leftWidth = getMaxLeftWidth();
        }

        int x = 0;
        for (Iterator<Option> it = optList.iterator(); it.hasNext();) {
            Option option = it.next();
            StringBuilder lineBuf = lineBufList.get(x++);
            if (lineBuf.length() <= leftWidth) {
                if (lineBuf.length() < leftWidth) {
                    lineBuf.append(OptionUtils.createPadding(leftWidth - lineBuf.length()));
                }
                lineBuf.append(dpad);
                if (option.getDescription() != null) {
                    lineBuf.append(option.getDescription());
                }
                renderWrappedText(sb, getWidth(), leftWidth + getDescPad(), lineBuf.toString());
            } else {
                sb.append(lineBuf).append(NEW_LINE);
                if (option.getDescription() != null) {
                    String line = OptionUtils.createPadding(leftWidth + getDescPad()) + option.getDescription();
                    renderWrappedText(sb, getWidth(), leftWidth + getDescPad(), line);
                }
            }
            if (it.hasNext()) {
                sb.append(NEW_LINE);
            }
        }
        return leftWidth;
    }
private int renderOptions ( StringBuilder sb , Collection < Option > options ) { String lpad = OptionUtils . createPadding ( getLeftPad ( ) ) ; String dpad = OptionUtils . createPadding ( getDescPad ( ) ) ; int leftWidth = 0 ; List < StringBuilder > lineBufList = new ArrayList < > ( ) ; Collection < Option > optList = options ; if ( optList . size ( ) > 1 && getOptionComparator ( ) != null ) { List < Option > optList2 = new ArrayList < > ( optList ) ; optList2 . sort ( getOptionComparator ( ) ) ; optList = optList2 ; } for ( Option option : optList ) { StringBuilder lineBuf = new StringBuilder ( ) ; if ( option . getName ( ) == null ) { lineBuf . append ( lpad ) . append ( LONG_OPTION_PREFIX ) . append ( option . getLongName ( ) ) ; } else { lineBuf . append ( lpad ) . append ( OPTION_PREFIX ) . append ( option . getName ( ) ) ; if ( option . hasLongName ( ) ) { lineBuf . append ( ", " ) . append ( LONG_OPTION_PREFIX ) . append ( option . getLongName ( ) ) ; } } if ( option . hasValue ( ) ) { String argName = option . getValueName ( ) ; if ( argName != null && argName . isEmpty ( ) ) { lineBuf . append ( ' ' ) ; } else { lineBuf . append ( option . isWithEqualSign ( ) ? '=' : LONG_OPTION_SEPARATOR ) ; lineBuf . append ( ARG_BRACKET_OPEN ) . append ( argName != null ? argName : getArgName ( ) ) . append ( ARG_BRACKET_CLOSE ) ; } } lineBufList . add ( lineBuf ) ; leftWidth = ( lineBuf . length ( ) > leftWidth ? lineBuf . length ( ) : leftWidth ) ; } if ( leftWidth > getMaxLeftWidth ( ) ) { leftWidth = getMaxLeftWidth ( ) ; } int x = 0 ; for ( Iterator < Option > it = optList . iterator ( ) ; it . hasNext ( ) ; ) { Option option = it . next ( ) ; StringBuilder lineBuf = lineBufList . get ( x ++ ) ; if ( lineBuf . length ( ) <= leftWidth ) { if ( lineBuf . length ( ) < leftWidth ) { lineBuf . append ( OptionUtils . createPadding ( leftWidth - lineBuf . length ( ) ) ) ; } lineBuf . append ( dpad ) ; if ( option . getDescription ( ) != null ) { lineBuf . append ( option . getDescription ( ) ) ; } renderWrappedText ( sb , getWidth ( ) , leftWidth + getDescPad ( ) , lineBuf . toString ( ) ) ; } else { sb . append ( lineBuf ) . append ( NEW_LINE ) ; if ( option . getDescription ( ) != null ) { String line = OptionUtils . createPadding ( leftWidth + getDescPad ( ) ) + option . getDescription ( ) ; renderWrappedText ( sb , getWidth ( ) , leftWidth + getDescPad ( ) , line ) ; } } if ( it . hasNext ( ) ) { sb . append ( NEW_LINE ) ; } } return leftWidth ; }
Render the specified Options and return the rendered Options
in a StringBuilder.

@param sb the StringBuilder to place the rendered Options into
@param options the command line Options
@return the longest opt string's length