fix(D-01): compact constructor defaults null componentConfigs to empty (RISK-004)
Add compact constructor to DataDrivenItemDefinition that defaults null componentConfigs to Map.of(). This makes the field guaranteed non-null, allowing removal of null checks in hasComponent() and DataDrivenItemRegistry.buildComponentHolders().
This commit is contained in:
@@ -105,8 +105,13 @@ public record DataDrivenItemDefinition(
|
||||
Map<ComponentType, JsonObject> componentConfigs
|
||||
) {
|
||||
|
||||
/** Compact constructor: default null componentConfigs to empty immutable map. */
|
||||
public DataDrivenItemDefinition {
|
||||
if (componentConfigs == null) componentConfigs = Map.of();
|
||||
}
|
||||
|
||||
/** Check whether this definition declares a given component type. */
|
||||
public boolean hasComponent(ComponentType type) {
|
||||
return componentConfigs != null && componentConfigs.containsKey(type);
|
||||
return componentConfigs.containsKey(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,14 +185,12 @@ public final class DataDrivenItemRegistry {
|
||||
DataDrivenItemDefinition def = entry.getValue();
|
||||
Map<ComponentType, IItemComponent> components =
|
||||
new EnumMap<>(ComponentType.class);
|
||||
if (def.componentConfigs() != null) {
|
||||
for (Map.Entry<ComponentType, JsonObject> compEntry :
|
||||
def.componentConfigs().entrySet()) {
|
||||
components.put(
|
||||
compEntry.getKey(),
|
||||
compEntry.getKey().create(compEntry.getValue())
|
||||
);
|
||||
}
|
||||
for (Map.Entry<ComponentType, JsonObject> compEntry :
|
||||
def.componentConfigs().entrySet()) {
|
||||
components.put(
|
||||
compEntry.getKey(),
|
||||
compEntry.getKey().create(compEntry.getValue())
|
||||
);
|
||||
}
|
||||
holders.put(
|
||||
entry.getKey(),
|
||||
|
||||
Reference in New Issue
Block a user