Engine { public void update() { if (update) { throw new IllegalStateException("Cannot nest calls to update()"); } update = true; flush(); for (EntitySystem system : systems) { system.update(); flush(); } update = false; } Engine(EngineConfig config); @Experimental EngineState getState(); void wire(Object object); void unwire(Object object); void update(); void reset(); int createEntity(); void destroyEntity(int entity); EntitySet getEntities(); Family getFamily(FamilyConfig config); T getSystem(Class<T> systemType); T getSystem(Class<T> systemType, boolean optional); EntitySystem[] getSystems(); Mapper<T> getMapper(Class<T> componentType);  }
@Test public void testEntitySystemPriority() { final List<EntitySystem> initializedSystems = new ArrayList<>(); final List<EntitySystem> updatedSystems = new ArrayList<>(); abstract class OrderSystem extends EntitySystem { @Override protected final void initialize() { initializedSystems.add(this); } @Override protected final void update() { updatedSystems.add(this); } } EntitySystem entitySystemA = new OrderSystem() { @Override public String toString() { return "A"; } }; EntitySystem entitySystemB = new OrderSystem() { @Override public String toString() { return "B"; } }; EntitySystem entitySystemC = new OrderSystem() { @Override public String toString() { return "C"; } }; EntitySystem entitySystemD = new OrderSystem() { @Override public String toString() { return "D"; } }; EntitySystem entitySystemE = new OrderSystem() { @Override public String toString() { return "E"; } }; Engine engine = new Engine(new EngineConfig() .addSystem(entitySystemA, Priority.DEFAULT) .addSystem(entitySystemB, Priority.DEFAULT) .addSystem(entitySystemC, Priority.HIGH) .addSystem(entitySystemD, Priority.LOWEST) .addSystem(entitySystemE, Priority.DEFAULT)); assertEquals(Arrays.asList(entitySystemC, entitySystemA, entitySystemB, entitySystemE, entitySystemD), initializedSystems); initializedSystems.clear(); engine.update(); assertEquals(Arrays.asList(entitySystemC, entitySystemA, entitySystemB, entitySystemE, entitySystemD), updatedSystems); updatedSystems.clear(); }