package com.imnotjames.tribbleengine.entity;

import com.imnotjames.tribbleengine.Family;

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

public class Entity {
	private static int singletonIndex = 0;

	private int index;

	private List<Component> components;

	private Family family;

	public Entity() {
		this.index = Entity.singletonIndex++;

		this.family = new Family();
		this.components = new ArrayList<Component>();
	}

	public int getIndex() {
		return this.index;
	}

	public Family getFamily() {
		return this.family;
	}

	public void addComponent(Component component) {
		if (component == null) {
			return;
		}

		if (this.hasComponent(component)) {
			throw new IllegalArgumentException("Entity already has component of type " + component.getClass());
		}

		this.components.add(component);

		this.family.addComponentType(component.getClass());
	}

	public Component[] getComponents() {
		return this.components.toArray(new Component[this.components.size()]);
	}

	public boolean hasComponent(Component component) {
		return this.hasComponent(component.getClass());
	}

	public boolean hasComponent(Class<? extends Component> componentType) {
		return this.family.hasComponentType(componentType);
	}
}

@@ -972,24 +972,246 @@
 ze()%5D);%0A%09%7D%0A%0A
+%09public Component getComponent(Class%3C? extends Component%3E componentType) %7B%0A%09%09for (Component component : this.components) %7B%0A%09%09%09if (component.getClass() == componentType) %7B%0A%09%09%09%09return component;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return null;%0A%09%7D%0A%0A
 %09public bool

add Entity.getComponent()