*| [JavaECS](../../README.md) | [docs](../overview.md) | [component](./dir.md) | ComponentManager[]().md* # Component Array | **In this Section** | |-| | [About](#about) | | [Implementation](#implementation) | | [Constructors](#constructors) | | [Methods](#methods) | | [Fields](#fields) | | [Examples](#examples)| | [Notes](#notes)| ## About The `ComponentArray` class defines the a common structure that all component data is stored in. ## Implementation Associatively maps an entity to the index position of its component data. See [ComponentManager.java](/BrychanD/JavaECS/src/branch/master/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java) for the full implementation. ## Constructors Default constructor ``` java public ComponentManager(){} ```
## Methods ### addComponentToEntity ``` java protected void addComponentToEntity(Type componentType, Object componentData, int entity); ``` Adds the specified component to the provided entity. Returns `true` if successful, `false` if the component is already associated to the entity.
### entityDestroyed ``` java public void entityDestroyed(int entity); ``` Signals to the `ComponentManager` the entity was destroyed. All component data references should be removed.
### getComponent ``` java public Object getComponent(Type componentType, int entity); ``` Gets the component data associated with the entity, or `null` if it was not found. * The result of this operation should be cast back to the specified `Type`
### getComponentIndex ``` java protected Integer getComponentIndex(Type type); ``` Gets the registration index of the provided component type. Returns the index, or `-1` if the component isn't registered.
### getComponentType ``` java protected Type getComponentType(Integer index); ``` Gets the registration type of the provided component index. Returns the index, or `null` if the component isn't registered.
### moveComponentData ``` java protected void moveComponentData(int sourceEntity, int destinationEntity, Type component); ``` Moves a single component data from one entity to another. Returns `true` if the component was moved successfully, else `false`.
### moveAllComponentData ``` java protected void moveAllComponentData(int sourceEntity, int destinationEntity, BitSet sourceRegistrations); ``` Moves all component data from one entity to another.
### registerComponent ``` java protected boolean registerComponent(Type type); ``` Registers the component type. Returns `true` if successful, else `false`.
### removeComponentFromEntity ``` java public boolean removeComponentFromEntity(Type componentType, int entity); ``` Removes the specified component from the entity. Returns `true` if successful, else `false`.
## Fields ### componentArrays ``` java private Map componentArrays = new HashMap<>(); ``` Maps the component `Type` to its [ComponentArray](./ComponentArray.md)
### componentPosIndex ``` java private Map componentPosIndex = new HashMap<>(); ``` The mapped list of component types to the registration indices.
### indexComponentType ``` java private Map indexComponentType = new HashMap<>(); ``` The mapped list of registration indices to component types.