automation around outputs section #197
refactoring: extract helper class
This commit is contained in:
parent
2e97642dae
commit
a6800cd384
|
@ -0,0 +1,27 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.BitState;
|
||||
import com.rusefi.ConfigField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FieldIterator {
|
||||
private final List<ConfigField> tsFields;
|
||||
BitState bitState = new BitState();
|
||||
ConfigField prev = ConfigField.VOID;
|
||||
ConfigField next;
|
||||
ConfigField cf;
|
||||
|
||||
public FieldIterator(List<ConfigField> tsFields) {
|
||||
this.tsFields = tsFields;
|
||||
}
|
||||
|
||||
public void start(int index) {
|
||||
next = index == tsFields.size() - 1 ? ConfigField.VOID : tsFields.get(index + 1);
|
||||
cf = tsFields.get(index);
|
||||
}
|
||||
|
||||
public void end() {
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
}
|
||||
}
|
|
@ -36,18 +36,16 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
|
||||
private int writeJavaFields(List<ConfigField> tsFields, String prefix, int tsPosition) throws IOException {
|
||||
BitState bitState = new BitState();
|
||||
ConfigField prev = ConfigField.VOID;
|
||||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
ConfigField next = i == tsFields.size() - 1 ? ConfigField.VOID : tsFields.get(i + 1);
|
||||
ConfigField cf = tsFields.get(i);
|
||||
iterator.start(i);
|
||||
// skip duplicate names
|
||||
if (cf.getName().equals(prev.getName()) || cf.isDirective())
|
||||
if (iterator.cf.getName().equals(iterator.prev.getName()) || iterator.cf.isDirective())
|
||||
continue;
|
||||
tsPosition = writeOneField(cf, prefix, tsPosition, next, bitState.get());
|
||||
tsPosition = writeOneField(iterator.cf, prefix, tsPosition, iterator.next, iterator.bitState.get());
|
||||
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
prev = cf;
|
||||
iterator.prev = iterator.cf;
|
||||
iterator.end();
|
||||
}
|
||||
return tsPosition;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.rusefi.*;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.rusefi.ToolUtil.EOL;
|
||||
|
||||
|
@ -100,27 +100,26 @@ public class TsOutput {
|
|||
}
|
||||
|
||||
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Writer tsHeader, int tsPosition) throws IOException {
|
||||
BitState bitState = new BitState();
|
||||
ConfigField prev = ConfigField.VOID;
|
||||
List<ConfigField> tsFields = configStructure.tsFields;
|
||||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
int prevTsPosition = tsPosition;
|
||||
for (int i = 0; i < configStructure.tsFields.size(); i++) {
|
||||
ConfigField next = i == configStructure.tsFields.size() - 1 ? ConfigField.VOID : configStructure.tsFields.get(i + 1);
|
||||
ConfigField cf = configStructure.tsFields.get(i);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
|
||||
// if duplicate names, use previous position
|
||||
if (cf.getName().equals(prev.getName())) {
|
||||
if (iterator.cf.getName().equals(iterator.prev.getName())) {
|
||||
tsPosition = prevTsPosition;
|
||||
}
|
||||
|
||||
// Update 'prev' state needed for duplicate names recognition
|
||||
if (!cf.isDirective()) {
|
||||
if (!iterator.cf.isDirective()) {
|
||||
prevTsPosition = tsPosition;
|
||||
prev = cf;
|
||||
iterator.prev = iterator.cf;
|
||||
}
|
||||
|
||||
tsPosition = writeTunerStudio(cf, prefix, tsHeader, tsPosition, next, bitState.get());
|
||||
tsPosition = writeTunerStudio(iterator.cf, prefix, tsHeader, tsPosition, iterator.next, iterator.bitState.get());
|
||||
|
||||
bitState.incrementBitIndex(cf, next);
|
||||
iterator.end();
|
||||
}
|
||||
return tsPosition;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue