| 25 | import java.util.LinkedList; |
| 26 | |
| 27 | public class ScreenBuffer implements Iterable<Object>, Serializable, Screenable { |
| 28 | |
| 29 | /** . */ |
| 30 | private final LinkedList<Object> chunks; |
| 31 | |
| 32 | /** . */ |
| 33 | private Style current; |
| 34 | |
| 35 | /** . */ |
| 36 | private Style next; |
| 37 | |
| 38 | /** Where we flush. */ |
| 39 | private final ScreenContext out; |
| 40 | |
| 41 | public ScreenBuffer() { |
| 42 | this.chunks = new LinkedList<Object>(); |
| 43 | this.current = Style.style(); |
| 44 | this.next = Style.style(); |
| 45 | this.out = null; |
| 46 | } |
| 47 | |
| 48 | public ScreenBuffer(ScreenContext out) { |
| 49 | this.chunks = new LinkedList<Object>(); |
| 50 | this.current = Style.style(); |
| 51 | this.next = Style.style(); |
| 52 | this.out = out; |
| 53 | } |
| 54 | |
| 55 | public Iterator<Object> iterator() { |
| 56 | return chunks.iterator(); |
| 57 | } |
| 58 | |
| 59 | public void format(Format format, Appendable appendable) throws IOException { |
| 60 | format.begin(appendable); |
| 61 | for (Object chunk : this) { |
| 62 | if (chunk instanceof Style) { |
| 63 | format.write((Style)chunk, appendable); |
| 64 | } else if (chunk instanceof CLS) { |
| 65 | format.cls(appendable); |
| 66 | } else { |
| 67 | format.write((CharSequence)chunk, appendable); |
| 68 | } |
| 69 | } |
| 70 | format.end(appendable); |
| 71 | } |
| 72 | |
| 73 | public ScreenBuffer append(Iterable<?> data) throws NullPointerException { |
| 74 | for (Object o : data) { |
| 75 | append(o); |
| 76 | } |
| 77 | return this; |
| 78 | } |
| 79 | |
| 80 | public ScreenBuffer append(Object... data) throws NullPointerException { |
| 81 | for (Object o : data) { |
| 82 | append(o); |
| 83 | } |
| 84 | return this; |
nothing calls this directly
no outgoing calls
no test coverage detected