public TextElement(Iterable<Object> stream, int minWidth) { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // Determine width int width = width(0, stream.iterator(), null, null); // this.minWidth = Math.min(width, minWidth); this.stream = stream; this.width = width; }
private static int width(int width, Iterator<Object> stream, CharSequence current, Integer from) { while (current == null) { if (stream.hasNext()) { Object next = stream.next(); if (next instanceof CharSequence) { current = (CharSequence)next; from = 0; } } else { break; } } if (current == null) { return width; } else { int pos = Utils.indexOf(current, from, '\n'); if (pos == -1) { return width(width + current.length() - from, stream, current, from); } else { return Math.max(width + pos - from, width(0, stream, null, 0)); } } }
public TextElement(Iterable<Object> stream, int minWidth) { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // Determine width int width = width(0, stream.iterator(), null, null); // this.minWidth = Math.min(width, minWidth); this.stream = stream; this.width = width; }
public TextElement(Iterable<Chunk> stream, int minWidth) { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // Determine width int width = width(0, stream.iterator(), null, null); // this.minWidth = Math.min(width, minWidth); this.stream = stream; this.width = width; }
public TextElement(Iterable<Object> stream, int minWidth) { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // Determine width int width = width(0, stream.iterator(), null, null); // this.minWidth = Math.min(width, minWidth); this.stream = stream; this.width = width; }
private static int width(int width, Iterator<Object> stream, CharSequence current, Integer from) { while (current == null) { if (stream.hasNext()) { Object next = stream.next(); if (next instanceof CharSequence) { current = (CharSequence)next; from = 0; } } else { break; } } if (current == null) { return width; } else { int pos = Utils.indexOf(current, from, '\n'); if (pos == -1) { return width(width + current.length() - from, stream, current, from); } else { return Math.max(width + pos - from, width(0, stream, null, 0)); } } }
private static int width(int width, Iterator<Object> stream, CharSequence current, Integer from) { while (current == null) { if (stream.hasNext()) { Object next = stream.next(); if (next instanceof CharSequence) { current = (CharSequence)next; from = 0; } } else { break; } } if (current == null) { return width; } else { int pos = Utils.indexOf(current, from, '\n'); if (pos == -1) { return width(width + current.length() - from, stream, current, from); } else { return Math.max(width + pos - from, width(0, stream, null, 0)); } } }
private static int width(int width, Iterator<Chunk> stream, Text current, Integer from) { while (current == null) { if (stream.hasNext()) { Chunk next = stream.next(); if (next instanceof Text) { current = (Text)next; from = 0; } } else { break; } } if (current == null) { return width; } else { int pos = Utils.indexOf(current.getText(), from, '\n'); if (pos == -1) { return width(width + current.getText().length() - from, stream, current, from); } else { return Math.max(width + pos - from, width(0, stream, null, 0)); } } }