Skip to content

Commit f9e0916

Browse files
committed
Refactored component initialization.
1 parent b18fd9c commit f9e0916

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

firebase-common/src/main/java/com/google/firebase/components/ComponentRuntime.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,32 @@ public ComponentRuntime(
6060
CycleDetector.detect(componentsToAdd);
6161

6262
for (Component<?> component : componentsToAdd) {
63-
register(component);
64-
}
65-
validateDependencies();
63+
Lazy<?> lazy =
64+
new Lazy<>(
65+
() ->
66+
component.getFactory().create(new RestrictedComponentContainer(component, this)));
6667

68+
components.put(component, lazy);
69+
}
70+
processInstanceComponents();
6771
processSetComponents();
6872
}
6973

74+
private void processInstanceComponents() {
75+
for (Map.Entry<Component<?>, Lazy<?>> entry : components.entrySet()) {
76+
Component<?> component = entry.getKey();
77+
if (!component.isValue()) {
78+
return;
79+
}
80+
81+
Lazy<?> lazy = entry.getValue();
82+
for (Class<?> anInterface : component.getProvidedInterfaces()) {
83+
lazyInstanceMap.put(anInterface, lazy);
84+
}
85+
}
86+
validateDependencies();
87+
}
88+
7089
/** Populates lazySetMap to make set components available for consumption via set dependencies. */
7190
private void processSetComponents() {
7291
Map<Class<?>, Set<Lazy<?>>> setIndex = new HashMap<>();
@@ -140,20 +159,6 @@ public void initializeEagerComponents(boolean isDefaultApp) {
140159
eventBus.enablePublishingAndFlushPending();
141160
}
142161

143-
private <T> void register(Component<T> component) {
144-
Lazy<T> lazy =
145-
new Lazy<>(
146-
() -> component.getFactory().create(new RestrictedComponentContainer(component, this)));
147-
148-
components.put(component, lazy);
149-
if (!component.isValue()) {
150-
return;
151-
}
152-
for (Class<? super T> anInterface : component.getProvidedInterfaces()) {
153-
lazyInstanceMap.put(anInterface, lazy);
154-
}
155-
}
156-
157162
private void validateDependencies() {
158163
for (Component<?> component : components.keySet()) {
159164
for (Dependency dependency : component.getDependencies()) {

0 commit comments

Comments
 (0)