package net.afterlifelochie.fontbox.document;

import java.util.ArrayList;

/**
 * Document class. Used to contain an ordered list of Elements which are later
 * transformed into renderable Elements for the book renderer.
 * 
 * @author AfterLifeLochie
 */
public class Document {

	/** The list of elements in the document */
	public ArrayList<Element> elements;

	/**
	 * Creates a new blank Document
	 */
	public Document() {
		this.elements = new ArrayList<Element>();
	}

	/**
	 * <p>
	 * Pushes an element onto the end of the document.
	 * </p>
	 * <p>
	 * The element must not already exist in the document. If the element
	 * already exists in the document, an {@link IllegalArgumentException} will
	 * be thrown.
	 * </p>
	 * 
	 * @param element
	 *            The element to add
	 */
	public void push(Element element) {
		if (elements.contains(element))
			throw new IllegalArgumentException("Element already exists in tree!");
		elements.add(element);
	}

	/**
	 * <p>
	 * Removes an element from the end of the document and returns it. If the
	 * document is empty, null will be returned.
	 * </p>
	 * 
	 * @return The element on the end of the document, or null if the document
	 *         is empty
	 */
	public Element pop() {
		if (elements.size() == 0)
			return null;
		return elements.remove(elements.size() - 1);
	}

	/**
	 * <p>
	 * Returns the element from the beginning of the document. If the document
	 * is empty, null is returned.
	 * </p>
	 * 
	 * @return The first element in the document, or null
	 */
	public Element head() {
		return elements.get(0);
	}

	/**
	 * <p>
	 * Returns last element from the end of the document. If the document is
	 * empty, null is returned.
	 * </p>
	 * 
	 * @return The last element in the document, or null
	 */
	public Element tail() {
		return elements.get(elements.size() - 1);
	}

}

@@ -70,16 +70,40 @@
 ayList;%0D
+%0Aimport java.util.List;%0D
 %0A%0D%0A/**%0D%0A
@@ -1018,32 +1018,492 @@
 lement);%0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * %3Cp%3E%0D%0A%09 * Pushes a list of elements onto the end of the document.%0D%0A%09 * %3C/p%3E%0D%0A%09 * %3Cp%3E%0D%0A%09 * Each element must not already exist in the document. If an element%0D%0A%09 * already exists in the document, an %7B@link IllegalArgumentException%7D will%0D%0A%09 * be thrown.%0D%0A%09 * %3C/p%3E%0D%0A%09 * %0D%0A%09 * @param elements%0D%0A%09 *            The elements to add%0D%0A%09 */%0D%0A%09public void pushAll(List%3CElement%3E elements) %7B%0D%0A%09%09for (Element ez : elements)%0D%0A%09%09%09if (ez != null)%0D%0A%09%09%09%09push(ez);%0D%0A%09%7D%0D%0A%0D%0A
 %09/**%0D%0A%09 * %3Cp%3E%0D%0A%09

Add Document.pushAll()