package ch.flurischt.html2rtf;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static com.tutego.jrtf.RtfPara.p;

import com.tutego.jrtf.RtfPara;
import com.tutego.jrtf.RtfText;

import static com.tutego.jrtf.RtfText.text;

public class ElementContainer {

	private List<Object> content = new LinkedList<Object>();

	public void add(Object o) {
		if (o instanceof ElementContainer)
			content.addAll(((ElementContainer) o).content);
		else if (o != null)
			content.add(o);
	}

	public List<RtfText> asTextList() {
		List<RtfText> list = new ArrayList<RtfText>();
		for (Object o : content) {
			if (o instanceof RtfText)
				list.add((RtfText) o);
			else if (o instanceof String) {
				list.add(text((String) o));
			} else
				throw new RuntimeException("WTF?");
		}
		return list;
	}

	public List<RtfPara> asParagraph() {
		List<RtfPara> paras = new ArrayList<RtfPara>();
		// TODO this makes a paragraph out of every text. stupid...
		for (Object o : content) {
			paras.add(p(o));
		}

		return paras;
	}

}

@@ -828,28 +828,106 @@
 %7D%0A%0A%09
+/**%0A%09 * puts the whole content of this container into a paragraph%0A%09 * @return%0A%09 */%0A%09
 public 
-List%3C
 RtfPara
-%3E
  asP
@@ -945,171 +945,221 @@
 %7B%0A%09%09
-List%3CRtfPara%3E paras = new ArrayList%3CRtfPara%3E();%0A%09%09// TODO this makes a paragraph out of every text. stupid...%0A%09%09for (Object o : content) %7B%0A%09%09%09paras.add(p(o)
+//TODO remove all Collections and switch to arrays%0A%09%09List%3CRtfText%3E texts = asTextList();%0A%09%09RtfText%5B%5D textArray = new RtfText%5Btexts.size()%5D;%0A%0A%09%09for(int i=0;i%3CtextArray.length;i++)%0A%09%09%09textArray%5Bi%5D = texts.get(i
 );%0A%09%09
-%7D%0A
 %0A%09%09r
@@ -1169,12 +1169,19 @@
 rn p
-aras
+(textArray)
 ;%0A%09%7D

remove unnecessary paragraphs. complex-test now works