class UIFrame extends UIElement {

	@Override
	public Object deepCopy() {
		final int attrSize = attributes != null ? attributes.size() : 0;
		final int childrenSize = children != null ? children.size() : 0;
		final UIFrame clone = new UIFrame(getName(), attrSize, childrenSize);
		clone.type = type;
		if (childrenSize > 0) {
			for (int i = 0; i < childrenSize; i++) {
				clone.children.add((UIElement) children.get(i).deepCopy());
			}
		}
		if (attrSize > 0) {
			for (int i = 0; i < attrSize; i++) {
				clone.attributes.add((UIAttribute) attributes.get(i).deepCopy());
			}
		}
		if (relative != DFLT_RELATIVE) {
			clone.relative = new String[4];
			System.arraycopy(relative, 0, clone.relative, 0, 4);
		}
		if (offset != DFLT_OFFSET) {
			clone.offset = new String[4];
			System.arraycopy(offset, 0, clone.offset, 0, 4);
		}
		if (pos != DFLT_POS) {
			clone.pos = new String[4];
			System.arraycopy(pos, 0, clone.pos, 0, 4);
		}
		return clone;
	}

}

class UIFrameTest {

	@Test
	void deepCopy() {

		final UIFrame frame = new UIFrame("UIFrameTest_setAnchor");
		
		frame.setAnchor("$parent", "0");
		assertEquals("$parent", frame.getAnchorRelative(UIAnchorSide.TOP));
		assertEquals("$parent", frame.getAnchorRelative(UIAnchorSide.LEFT));
		assertEquals("$parent", frame.getAnchorRelative(UIAnchorSide.BOTTOM));
		assertEquals("$parent", frame.getAnchorRelative(UIAnchorSide.RIGHT));
		assertEquals("MIN", frame.getAnchorPos(UIAnchorSide.TOP));
		assertEquals("MIN", frame.getAnchorPos(UIAnchorSide.LEFT));
		assertEquals("MAX", frame.getAnchorPos(UIAnchorSide.BOTTOM));
		assertEquals("MAX", frame.getAnchorPos(UIAnchorSide.RIGHT));
		assertEquals("0", frame.getAnchorOffset(UIAnchorSide.TOP));
		assertEquals("0", frame.getAnchorOffset(UIAnchorSide.LEFT));
		assertEquals("0", frame.getAnchorOffset(UIAnchorSide.BOTTOM));
		assertEquals("0", frame.getAnchorOffset(UIAnchorSide.RIGHT));
		
		final UIFrame frame2 = (UIFrame) frame.deepCopy();
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.TOP));
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.LEFT));
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.BOTTOM));
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.RIGHT));
		assertEquals("MIN", frame2.getAnchorPos(UIAnchorSide.TOP));
		assertEquals("MIN", frame2.getAnchorPos(UIAnchorSide.LEFT));
		assertEquals("MAX", frame2.getAnchorPos(UIAnchorSide.BOTTOM));
		assertEquals("MAX", frame2.getAnchorPos(UIAnchorSide.RIGHT));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.TOP));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.LEFT));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.BOTTOM));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.RIGHT));
		
		frame2.setAnchor(UIAnchorSide.BOTTOM, "$Minimap", "mid", "11");
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.TOP));
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.LEFT));
		assertEquals("$Minimap", frame2.getAnchorRelative(UIAnchorSide.BOTTOM));
		assertEquals("$parent", frame2.getAnchorRelative(UIAnchorSide.RIGHT));
		assertEquals("MIN", frame2.getAnchorPos(UIAnchorSide.TOP));
		assertEquals("MIN", frame2.getAnchorPos(UIAnchorSide.LEFT));
		assertEquals("mid", frame2.getAnchorPos(UIAnchorSide.BOTTOM));
		assertEquals("MAX", frame2.getAnchorPos(UIAnchorSide.RIGHT));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.TOP));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.LEFT));
		assertEquals("11", frame2.getAnchorOffset(UIAnchorSide.BOTTOM));
		assertEquals("0", frame2.getAnchorOffset(UIAnchorSide.RIGHT));
		
	}

}