/**
		 * @param e entity
		 * @return the name of the group that this entity belongs to, null if none.
		 */
		public String GetGroupOf(Entity e) {
			int entityId = e.GetId();
			if(entityId < groupByEntity.GetCapacity()) {
				return groupByEntity.Get(entityId);
			}
			return null;
		}
		public void Change(Entity e) {
			bool contains = (systemBit & e.GetSystemBits()) == systemBit;
			bool interest = (typeFlags & e.GetTypeBits()) == typeFlags;
	
			if (interest && !contains && typeFlags > 0) {
				actives.Add(e.GetId(),e);
				e.AddSystemBit(systemBit);
				Added(e);
			} else if (!interest && contains && typeFlags > 0) {
				Remove(e);
			}
		}
		/**
		 * Set the group of the entity.
		 * 
		 * @param group group to set the entity into.
		 * @param e entity to set into the group.
		 */
		public void Set(String group, Entity e) {
			Remove(e); // Entity can only belong to one group.
			
			Bag<Entity> entities;
			if(!entitiesByGroup.TryGetValue(group,out entities)) {
				entities = new Bag<Entity>();
				entitiesByGroup.Add(group, entities);
			}
			entities.Add(e);
			
			groupByEntity.Set(e.GetId(), group);
		}
		/**
		 * Removes the provided entity from the group it is assigned to, if any.
		 * @param e the entity.
		 */
		public void Remove(Entity e) {
			int entityId = e.GetId();
			if(entityId < groupByEntity.GetCapacity()) {
				String group = groupByEntity.Get(entityId);
				if(group != null) {
					groupByEntity.Set(entityId, null);
					
					Bag<Entity> entities;
					if(entitiesByGroup.TryGetValue(group,out entities)) {
						entities.Remove(e);
					}
				}
			}
		}
 private void Remove(Entity e)
 {
     actives.Remove(e.GetId());
     e.RemoveSystemBit(systemBit);
     Removed(e);
 }