@Test @FixFor( "MODE-2322" ) public void shouldSupportPrimitiveArrays() { String text = StringUtil.createString("Error converting \"{2}\" from {0} to a {1}", byte[].class.getSimpleName(), "BinaryValue", new byte[] {-1}); assertEquals("Error converting \"[-1]\" from byte[] to a BinaryValue", text); }
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); 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]; 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(); }
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); 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]; 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(); } }
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); 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]; 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(); }
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); 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]; 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(); static String combineLines( String[] lines ); static String combineLines( String[] lines,
                                       char separator ); static List<String> splitLines( final String content ); static String join( Object[] values,
                               String delimiter ); static String join( Iterable<?> values,
                               String delimiter ); static String createString( String pattern,
                                       Object... parameters ); static String createString( final char charToRepeat,
                                       int numberOfRepeats ); static String setLength( String original,
                                    int length,
                                    char padChar ); static String justify( Justify justify,
                                  String str,
                                  final int width,
                                  char padWithChar ); static String justifyRight( String str,
                                       final int width,
                                       char padWithChar ); static String justifyLeft( String str,
                                      final int width,
                                      char padWithChar ); static String justifyCenter( String str,
                                        final int width,
                                        char padWithChar ); static String truncate( Object obj,
                                   int maxLength ); static String truncate( Object obj,
                                   int maxLength,
                                   String suffix ); static String read( Reader reader ); static String read( InputStream stream ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static String getStackTrace( Throwable throwable ); static String normalize( String text ); static String getHexString( byte[] bytes ); static byte[] fromHexString( String hexadecimal ); static boolean isHexString( String hexadecimal ); static boolean isHexCharacter( char c ); static boolean isBlank( String str ); static boolean notBlank( String str ); static boolean containsAnyOf( String str,
                                         char... chars ); }
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); 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]; 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(); static String combineLines( String[] lines ); static String combineLines( String[] lines,
                                       char separator ); static List<String> splitLines( final String content ); static String join( Object[] values,
                               String delimiter ); static String join( Iterable<?> values,
                               String delimiter ); static String createString( String pattern,
                                       Object... parameters ); static String createString( final char charToRepeat,
                                       int numberOfRepeats ); static String setLength( String original,
                                    int length,
                                    char padChar ); static String justify( Justify justify,
                                  String str,
                                  final int width,
                                  char padWithChar ); static String justifyRight( String str,
                                       final int width,
                                       char padWithChar ); static String justifyLeft( String str,
                                      final int width,
                                      char padWithChar ); static String justifyCenter( String str,
                                        final int width,
                                        char padWithChar ); static String truncate( Object obj,
                                   int maxLength ); static String truncate( Object obj,
                                   int maxLength,
                                   String suffix ); static String read( Reader reader ); static String read( InputStream stream ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static String getStackTrace( Throwable throwable ); static String normalize( String text ); static String getHexString( byte[] bytes ); static byte[] fromHexString( String hexadecimal ); static boolean isHexString( String hexadecimal ); static boolean isHexCharacter( char c ); static boolean isBlank( String str ); static boolean notBlank( String str ); static boolean containsAnyOf( String str,
                                         char... chars ); static final String[] EMPTY_STRING_ARRAY; }