refactoring

This commit is contained in:
rusefillc 2022-04-17 14:37:17 -04:00
parent ca196a5de3
commit f69aa606a0
2 changed files with 90 additions and 102 deletions

View File

@ -7,10 +7,11 @@ import java.io.IOException;
import java.util.List;
public abstract class FieldsStrategy {
public void run(ReaderState state, ConfigStructure structure, int sensorTsPosition) throws IOException {
public int run(ReaderState state, ConfigStructure structure, int sensorTsPosition) throws IOException {
if (state.stack.isEmpty()) {
writeFields(structure.tsFields, "", sensorTsPosition);
return writeFields(structure.tsFields, "", sensorTsPosition);
}
return sensorTsPosition;
}
protected int writeFields(List<ConfigField> tsFields, String prefix, int tsPosition) throws IOException {

View File

@ -34,7 +34,10 @@ public class TsOutput {
return settingContextHelp;
}
private int writeOneField(FieldIterator it, String prefix, int tsPosition) throws IOException {
public void run(ReaderState state, ConfigStructure structure, int sensorTsPosition) throws IOException {
FieldsStrategy strategy = new FieldsStrategy() {
@Override
public int writeOneField(FieldIterator it, String prefix, int tsPosition) throws IOException {
ConfigField configField = it.cf;
ConfigField next = it.next;
int bitIndex = it.bitState.get();
@ -115,30 +118,14 @@ public class TsOutput {
tsHeader.append(EOL);
return tsPosition;
}
};
sensorTsPosition = strategy.run(state, structure, sensorTsPosition);
public void run(ReaderState state, ConfigStructure structure, int sensorTsPosition) throws IOException {
if (state.stack.isEmpty()) {
writeFields(structure.tsFields, "", sensorTsPosition);
tsHeader.append("; total TS size = " + sensorTsPosition + EOL);
}
}
protected int writeFields(List<ConfigField> tsFields, String prefix, int tsPosition) throws IOException {
FieldIterator iterator = new FieldIterator(tsFields);
for (int i = 0; i < tsFields.size(); i++) {
iterator.start(i);
tsPosition = writeOneField(iterator, prefix, tsPosition);
iterator.end();
}
if (prefix.isEmpty()) {
// empty prefix means top level
tsHeader.append("; total TS size = " + tsPosition + EOL);
}
return tsPosition;
}
private String handleTsInfo(String tsInfo, int multiplierIndex) {
try {
String[] fields = tsInfo.split("\\,");