/** * Given a set of {@code objects}, calls {@code toString} on each of them with the {@code builder} * and separates each object's output in the {@code builder} with a comma. */ public static void toStrings(TextBuilder builder, Iterable<?> objects) { boolean first = true; for (Object object : objects) { if (!first) { builder.append(", "); } builder.append(object.toString()); first = false; } }
/** * Given a set of {@code objects}, calls {@code toCompactString} on each of them with the {@code * builder} and separates each object's output in the {@code builder} with a comma. */ public static void toCompactStrings( TextBuilder builder, Iterable<? extends InternalBase> objects) { boolean first = true; for (InternalBase object : objects) { if (!first) { builder.append(", "); } object.toCompactString(builder); first = false; } }
public static void main(String[] args) { if (args.length != 1) { usage(); System.exit(0); } if (args[0].equals("plain")) { TextBuilder textBuilder = new TextBuilder(); Director director = new Director(textBuilder); director.construct(); String result = textBuilder.getResult(); System.out.println(result); } else if (args[0].equals("html")) { HTMLBuilder htmlBuilder = new HTMLBuilder(); Director director = new Director(htmlBuilder); director.construct(); String result = htmlBuilder.getResult(); System.out.println(result); } else { usage(); System.exit(0); } }
/** * Creates a TextBuilder internally and returns a string based on the {@code toVerboseString} * method described above. */ public String toVerboseString() { TextBuilder builder = new TextBuilder(); toVerboseString(builder); return builder.toString(); }
@Override public String toString() { TextBuilder builder = new TextBuilder(); toCompactString(builder); return builder.toString(); }