only:refactoring:extract part of functionality into `ComposedIniFieldMigrator` class #7476
This commit is contained in:
parent
ffab21f4d7
commit
ce085bfe3b
|
@ -5,7 +5,7 @@ import com.opensr5.ini.IniFileModel;
|
|||
import com.opensr5.ini.field.*;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.io.UpdateOperationCallbacks;
|
||||
import com.rusefi.maintenance.migration.DefaultIniFieldMigrator;
|
||||
import com.rusefi.maintenance.migration.ComposedIniFieldMigrator;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -69,7 +69,7 @@ public class IniFieldsAnalyzer {
|
|||
newValue.getRows()
|
||||
));
|
||||
} else {
|
||||
final Optional<String> migratedValue = DefaultIniFieldMigrator.INSTANCE.tryMigrateValue(
|
||||
final Optional<String> migratedValue = ComposedIniFieldMigrator.INSTANCE.tryMigrateValue(
|
||||
prevFieldEntry.getValue(),
|
||||
newField,
|
||||
prevValue.getValue(),
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.rusefi.maintenance.migration;
|
||||
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.rusefi.io.UpdateOperationCallbacks;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum ComposedIniFieldMigrator implements IniFieldMigrator {
|
||||
INSTANCE;
|
||||
|
||||
private final List<IniFieldMigrator> iniFieldMigrators = Arrays.asList(DefaultIniFieldMigrator.INSTANCE);
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<String> tryMigrateValue(
|
||||
final IniField prevField,
|
||||
final IniField newField,
|
||||
final String prevValue,
|
||||
final UpdateOperationCallbacks callbacks
|
||||
) {
|
||||
Optional<String> result = Optional.empty();
|
||||
for (final IniFieldMigrator migrator: iniFieldMigrators) {
|
||||
result = migrator.tryMigrateValue(prevField, newField, prevValue, callbacks);
|
||||
if (result.isPresent()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue