package com.ea.nimble; import com.ea.nimble.Log; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.ListIterator; import java.util.Map; /* loaded from: classes2.dex */ class ComponentManager implements LogSource { private Map m_components = new LinkedHashMap(); private Stage m_stage = Stage.CREATE; public enum Stage { CREATE, SETUP, READY, SUSPEND } @Override // com.ea.nimble.LogSource public String getLogSourceTitle() { return "Component"; } public Stage getStage() { return this.m_stage; } public void registerComponent(Component component, String str) { Log.Helper.LOGFUNC(this); if (!Utility.validString(str)) { Log.Helper.LOGF(this, "Cannot register component without valid componentId", new Object[0]); return; } if (component == null) { Log.Helper.LOGF(this, "Try to register invalid component with id: " + str, new Object[0]); return; } Component component2 = this.m_components.get(str); if (component2 == null) { Log.Helper.LOGI(this, "Register module: " + str, new Object[0]); } else { Log.Helper.LOGI(this, "Register module(overwrite): " + str, new Object[0]); } this.m_components.put(str, component); Stage stage = this.m_stage; Stage stage2 = Stage.SETUP; if (stage.compareTo(stage2) < 0) { return; } if (component2 != null) { if (this.m_stage.compareTo(stage2) >= 0) { if (this.m_stage.compareTo(Stage.SUSPEND) >= 0) { component2.resume(); } component2.cleanup(); } component2.teardown(); } component.setup(); if (this.m_stage.compareTo(Stage.READY) >= 0) { component.restore(); if (this.m_stage.compareTo(Stage.SUSPEND) >= 0) { component.suspend(); } } } public Component getComponent(String str) { return this.m_components.get(str); } public Component[] getComponentList(String str) { Log.Helper.LOGFUNC(this); ArrayList arrayList = new ArrayList(this.m_components.size()); for (Map.Entry entry : this.m_components.entrySet()) { if (entry.getKey().startsWith(str)) { arrayList.add(entry.getValue()); } } return (Component[]) arrayList.toArray(new Component[arrayList.size()]); } public void setup() { this.m_stage = Stage.SETUP; Iterator it = this.m_components.values().iterator(); while (it.hasNext()) { it.next().setup(); } } public void restore() { this.m_stage = Stage.READY; Iterator it = this.m_components.values().iterator(); while (it.hasNext()) { it.next().restore(); } } public void suspend() { ListIterator listIterator = new ArrayList(this.m_components.values()).listIterator(this.m_components.size()); this.m_stage = Stage.SUSPEND; while (listIterator.hasPrevious()) { ((Component) listIterator.previous()).suspend(); } } public void resume() { this.m_stage = Stage.READY; Iterator it = this.m_components.values().iterator(); while (it.hasNext()) { it.next().resume(); } } public void cleanup() { ListIterator listIterator = new ArrayList(this.m_components.values()).listIterator(this.m_components.size()); this.m_stage = Stage.CREATE; while (listIterator.hasPrevious()) { ((Component) listIterator.previous()).cleanup(); } } public void teardown() { ListIterator listIterator = new ArrayList(this.m_components.values()).listIterator(this.m_components.size()); this.m_stage = Stage.CREATE; while (listIterator.hasPrevious()) { ((Component) listIterator.previous()).teardown(); } } }