class StringUtil {

    public static String createString( String pattern,
                                       Object... parameters ) {
        CheckArg.isNotNull(pattern, "pattern");
        if (parameters == null) parameters = EMPTY_STRING_ARRAY;
        Matcher matcher = PARAMETER_COUNT_PATTERN.matcher(pattern);
        // CHECKSTYLE IGNORE check FOR NEXT 1 LINES
        StringBuffer text = new StringBuffer();
        int requiredParameterCount = 0;
        boolean err = false;
        while (matcher.find()) {
            int ndx = Integer.valueOf(matcher.group(1));
            if (requiredParameterCount <= ndx) {
                requiredParameterCount = ndx + 1;
            }
            if (ndx >= parameters.length) {
                err = true;
                matcher.appendReplacement(text, matcher.group());
            } else {
                Object parameter = parameters[ndx];

                // Automatically pretty-print arrays
                if (parameter != null && parameter.getClass().isArray()) {
                    if (parameter instanceof Object[]) {
                        parameter = Arrays.asList((Object[])parameter);
                    } else {
                        int length = Array.getLength(parameter);
                        List<Object> parameterAsList = new ArrayList<Object>(length);
                        for (int i = 0; i < length; i++) {
                            parameterAsList.add(Array.get(parameter, i));
                        }
                        parameter = parameterAsList;
                    }
                }

                matcher.appendReplacement(text, Matcher.quoteReplacement(parameter == null ? "null" : parameter.toString()));
            }
        }
        if (err || requiredParameterCount < parameters.length) {
            throw new IllegalArgumentException(
                                               CommonI18n.requiredToSuppliedParameterMismatch.text(parameters.length,
                                                                                                   parameters.length == 1 ? "" : "s",
                                                                                                   requiredParameterCount,
                                                                                                   requiredParameterCount == 1 ? "" : "s",
                                                                                                   pattern, text.toString()));
        }
        matcher.appendTail(text);

        return text.toString();
    }

    private  StringUtil();

}