Entities: Conditionals + Component members vs. O(1) Hash lookup of strategy
===

I'm building a new entity system in Java. I'm wondering whether my proposed method would cause any issues, architecture-wise or performance-wise.

I want:

    ...
    
    for (Entity entity : entities)
    {
    	for (Component component : entity.components)
    	{
    		entity.update(deltaTime);
    	}
    }
    
    ...

vs. the undesirable alternative:

    ...
    
    
    for (Entity entity : entities)
    {
    	if (entity.componentA != null)
    		entity.componentA.update(deltaTime);
    		
    	if (entity.componentB != null)
    		entity.componentB.update(deltaTime);
    	
    	//etc. for as many components as the entity might have.
    }
    
    ...

With the first approach, some things I've thought of in regard to the HashMap approach:

 - I would avoid unecessary conditionals (non-trivial when thousands of entities are having their `update()` called);
 - Read access time is O(1) on average (the only time you're likely to not get that is on a hash collision);
 - `HashMap.entrySet()` must be called to iterate over the collection using for-each syntax. As I understand it from the docs, "the collection [set] is backed by the map". However this does not tell me if HashMap is internally creating the set, each time `entrySet()` is called.




