package eu.greenlightning.hypercubepdf.layout;

public class HCPSplitLayout extends HCPSpacedLayout {

	private static final HCPSplitLayout NO_SPACING = new HCPSplitLayout(0);

	public static HCPSplitLayout getInstance() {
		return NO_SPACING;
	}

	public static HCPSplitLayout getInstance(float spacing) {
		return spacing == 0 ? NO_SPACING : new HCPSplitLayout(spacing);
	}

	private HCPSplitLayout(float spacing) {
		super(spacing);
	}
	
	@Override
	public float getSize(float[] sizes) {
		return sizes.length * getMaxSize(sizes) + getTotalSpacing(sizes);
	}

	@Override
	public HCPLayoutResults apply(HCPLayoutSpace space, float[] sizes) {
		float totalSpacing = getTotalSpacing(sizes);
		if (totalSpacing >= space.getLength())
			return HCPEmptyLayoutResults.INSTANCE;
		float elementSize = (space.getLength() - totalSpacing) / sizes.length;
		return new HCPSplitLayoutResults(space, sizes.length, elementSize, getSpacing());
	}

}

@@ -45,207 +45,962 @@
 t;%0A%0A
-public class HCPSplitLayout extends HCPSpacedLayout %7B%0A%0A%09private static final HCPSplitLayout NO_SPACING = new HCPSplitLayout(0);%0A%0A%09public static HCPSplitLayout getInstance() %7B%0A%09%09return NO_SPACING;%0A%09%7D%0A
+/**%0A * A layout algorithm which splits the available space equally among the elements, regardless of their preferred size.%0A * %3Cp%3E%0A * Always paints all elements unless there is not enough space for the spacing alone, in which case nothing is painted.%0A * %3Cp%3E%0A * This class is immutable.%0A * %0A * @author Green Lightning%0A */%0Apublic class HCPSplitLayout extends HCPSpacedLayout %7B%0A%0A%09private static final HCPSplitLayout NO_SPACING = new HCPSplitLayout(0);%0A%0A%09/**%0A%09 * Returns an %7B@link HCPSplitLayout%7D instance which places elements next to each other.%0A%09 * %0A%09 * @return an instance with no spacing%0A%09 */%0A%09public static HCPSplitLayout getInstance() %7B%0A%09%09return NO_SPACING;%0A%09%7D%0A%0A%09/**%0A%09 * Returns an %7B@link HCPSplitLayout%7D instance which maintains the specified spacing between two adjacent elements.%0A%09 * %0A%09 * @param spacing must be %7B@literal %3E= 0%7D%0A%09 * @return an instance with the specified spacing%0A%09 * @throws IllegalArgumentException if spacing is %7B@literal %3C 0%7D%0A%09 */
 %0A%09pu

Document HCPSplitLayout.