Удалил код первой попытки линивой инициализации

This commit is contained in:
Struchkov Mark 2022-07-15 08:13:34 +03:00
parent 29145fe093
commit 2a9413ab46
6 changed files with 4 additions and 47 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
</parent>
<artifactId>bot-context</artifactId>

View File

@ -12,7 +12,6 @@ public class UnitDefinition {
private String name;
private Object objectConfig;
private Method method;
private boolean lazy;
public String getName() {
return name;
@ -66,12 +65,4 @@ public class UnitDefinition {
this.dependentUnits.addAll(dependentUnitNames);
}
public boolean isLazy() {
return lazy;
}
public void setLazy(boolean lazy) {
this.lazy = lazy;
}
}

View File

@ -13,8 +13,6 @@ public @interface Unit {
String value() default "";
boolean lazy() default false;
boolean mainUnit() default false;
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
</parent>
<artifactId>bot-core</artifactId>

View File

@ -31,7 +31,6 @@ public class StorylineMaker {
private final Map<String, UnitDefinition> unitDefinitions = new HashMap<>();
private final Map<String, MainUnit> unitMap = new HashMap<>();
private final Set<String> lazyUnits = new HashSet<>();
private final Set<String> mainUnits = new HashSet<>();
public StorylineMaker(List<Object> unitConfigurations) {
@ -50,7 +49,6 @@ public class StorylineMaker {
generateUnitDefinitions();
try {
createUnitMap();
createLazy();
final Set<MainUnit> mainUnit = getMainUnit();
return new Storyline(mainUnit, unitMap);
} catch (IllegalAccessException | InvocationTargetException e) {
@ -66,43 +64,18 @@ public class StorylineMaker {
.collect(Collectors.toSet());
}
private void createLazy() throws IllegalAccessException, InvocationTargetException {
final List<UnitDefinition> lazyDefinitions = unitDefinitions.values().stream()
.filter(UnitDefinition::isLazy)
.toList();
for (UnitDefinition lazyDefinition : lazyDefinitions) {
final MainUnit lazyUnit = createUnit(lazyDefinition);
unitMap.put(lazyDefinition.getName(), lazyUnit);
for (String dependentUnit : lazyDefinition.getDependentUnits()) {
final MainUnit mainUnit = unitMap.get(dependentUnit);
final Set<MainUnit> nextUnits = mainUnit.getNextUnits();
if (nextUnits != null) {
nextUnits.add(lazyUnit);
}
}
}
}
private void createUnitMap() throws IllegalAccessException, InvocationTargetException {
for (UnitDefinition unitDefinition : unitDefinitions.values()) {
if (!unitMap.containsKey(unitDefinition.getName())) {
final Set<String> nextUnitNames = unitDefinition.getNextUnitNames();
if (nextUnitNames.isEmpty() || unitMap.keySet().containsAll(nextUnitNames)) {
createUnit(unitDefinition);
} else if (unitDefinition.isLazy()) {
createLazyUnit(unitDefinition);
}
}
}
}
private void createLazyUnit(UnitDefinition unitDefinition) {
final String unitName = unitDefinition.getName();
unitMap.put(unitName, LazyUnit.create(unitName, unitDefinition));
}
private MainUnit createUnit(UnitDefinition unitDefinition) throws IllegalAccessException, InvocationTargetException {
final Object objectConfig = unitDefinition.getObjectConfig();
final String currentUnitName = unitDefinition.getName();
final Method method = unitDefinition.getMethod();
@ -118,7 +91,6 @@ public class StorylineMaker {
unitMap.put(currentUnitName, newUnit);
final Set<String> dependentUnitsName = unitDefinition.getDependentUnits();
dependentUnitsName.removeAll(lazyUnits);
for (String dependentUnitName : dependentUnitsName) {
final Set<String> dependentNextUnitNames = unitDefinitions.get(dependentUnitName).getNextUnitNames();
if (unitMap.keySet().containsAll(dependentNextUnitNames)) {
@ -145,11 +117,7 @@ public class StorylineMaker {
unitDefinition.setName(unitName);
unitDefinition.setMethod(method);
unitDefinition.setObjectConfig(config);
unitDefinition.setLazy(unitConfig.lazy());
if (unitConfig.lazy()) {
lazyUnits.add(unitName);
}
if (unitConfig.mainUnit()) {
mainUnits.add(unitName);
}

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
<packaging>pom</packaging>
<modules>
@ -32,7 +32,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<godfather.ver>0.0.10</godfather.ver>
<godfather.ver>0.0.11</godfather.ver>
<godfather.context.ver>${godfather.ver}</godfather.context.ver>
<godfather.core.ver>${godfather.ver}</godfather.core.ver>