### Question:
ArrayUtil { static public String format(Array.Type type, Collection<?> values){ StringBuilder sb = new StringBuilder(values.size() * 16); boolean enableQuotes; switch(type){ case INT: case REAL: enableQuotes = false; break; case STRING: enableQuotes = true; break; default: throw new IllegalArgumentException(); } for(Object value : values){ if(value instanceof ComplexValue){ ComplexValue complexValue = (ComplexValue)value; value = complexValue.toSimpleValue(); } String string = value.toString(); if(sb.length() > 0){ sb.append(' '); } if(enableQuotes){ boolean quoted = ("").equals(string) || (string.indexOf(' ') > -1); if(quoted){ sb.append('\"'); } if(string.indexOf('\"') > -1){ for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\"'){ sb.append('\\'); } sb.append(c); } } else { sb.append(string); } if(quoted){ sb.append('\"'); } } else { sb.append(string); } } return sb.toString(); } private  ArrayUtil(); static List<String> parse(Array.Type type, String string); static String format(Array.Type type, Collection<?> values);  }### Answer:
@Test public void formatNumberArray(){ ComplexValue integerTwoWrapper = new ComplexValue(){ @Override public Object toSimpleValue(){ return 2; } }; assertEquals("1 2 3", ArrayUtil.format(Array.Type.INT, Arrays.asList(1, integerTwoWrapper, 3))); assertEquals("1.0 2.0 3.0", ArrayUtil.format(Array.Type.REAL, Arrays.asList(1d, 2d, 3d))); assertEquals("1 22 3", ArrayUtil.format(Array.Type.INT, Arrays.asList("1", "22", "3"))); }
@Test public void formatStringArray(){ assertEquals("", ArrayUtil.format(Array.Type.STRING, Collections.emptyList())); assertEquals("\"\"", ArrayUtil.format(Array.Type.STRING, Arrays.asList(""))); assertEquals("\"\" \" \"", ArrayUtil.format(Array.Type.STRING, Arrays.asList("", " "))); assertEquals("a b c", ArrayUtil.format(Array.Type.STRING, Arrays.asList("a", "b", "c"))); assertEquals("a \"\" b c", ArrayUtil.format(Array.Type.STRING, Arrays.asList("a", "", "b", "c"))); assertEquals("\"a b c\"", ArrayUtil.format(Array.Type.STRING, Arrays.asList("a b c"))); assertEquals("\\a \\b\\ c\\", ArrayUtil.format(Array.Type.STRING, Arrays.asList("\\a", "\\b\\", "c\\"))); assertEquals("ab \"a b\" \"with \\\"quotes\\\" \"", ArrayUtil.format(Array.Type.STRING, Arrays.asList("ab", "a b", "with \"quotes\" "))); }