Created
March 22, 2012 17:38
-
-
Save vmassol/2160618 to your computer and use it in GitHub Desktop.
Printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String append(Object... objects) | |
{ | |
StringBuffer buffer = new StringBuffer(); | |
for (int i = 0; i < objects.length; i += 2) { | |
String key = (String) objects[i]; | |
Object value = objects[i + 1]; | |
if (value instanceof List) { | |
appendList(buffer, key, (List) value); | |
} else { | |
appendLiteral(buffer, key, value); | |
} | |
if (i != objects.length - 2) { | |
append(' '); | |
} | |
} | |
return buffer.toString(); | |
} | |
private void appendLiteral(StringBuffer buffer, String key, Object value) | |
{ | |
buffer.append(String.format("%s = [%s]", key, value)); | |
} | |
private void appendList(StringBuffer buffer, String key, List values) | |
{ | |
buffer.append(key); | |
buffer.append(' '); | |
buffer.append('='); | |
buffer.append(' '); | |
buffer.append('['); | |
Iterator<String> it = values.listIterator(); | |
while (it.hasNext()) { | |
Object value = it.next(); | |
buffer.append('['); | |
buffer.append(value); | |
buffer.append(']'); | |
if (it.hasNext()) { | |
buffer.append(','); | |
buffer.append(' '); | |
} | |
} | |
buffer.append(']'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment