refactoring
This commit is contained in:
parent
9ba21589f8
commit
254e31bc4c
|
@ -1,4 +1,56 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.output.ConfigStructure;
|
||||
|
||||
public interface ConfigField {
|
||||
ConfigStructure getStructureType();
|
||||
|
||||
boolean isArray();
|
||||
|
||||
String getTrueName();
|
||||
|
||||
String getFalseName();
|
||||
|
||||
boolean isBit();
|
||||
|
||||
boolean isDirective();
|
||||
|
||||
int getSize(ConfigField next);
|
||||
|
||||
int[] getArraySizes();
|
||||
|
||||
String getComment();
|
||||
|
||||
String getName();
|
||||
|
||||
String getType();
|
||||
|
||||
int getElementSize();
|
||||
|
||||
boolean isIterate();
|
||||
|
||||
boolean isHasAutoscale();
|
||||
|
||||
ReaderState getState();
|
||||
|
||||
String getTsInfo();
|
||||
|
||||
boolean isFsioVisible();
|
||||
|
||||
String autoscaleSpec();
|
||||
|
||||
double autoscaleSpecNumber();
|
||||
|
||||
Pair<Integer, Integer> autoscaleSpecPair();
|
||||
|
||||
String[] getTokens();
|
||||
|
||||
String getUnits();
|
||||
|
||||
double getMin();
|
||||
|
||||
double getMax();
|
||||
|
||||
int getDigits();
|
||||
}
|
||||
|
|
|
@ -115,26 +115,32 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigStructure getStructureType() {
|
||||
return getState().getStructures().get(getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArray() {
|
||||
return arraySizeVariableName != null || arraySizes.length != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrueName() {
|
||||
return trueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFalseName() {
|
||||
return falseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBit() {
|
||||
return BOOLEAN_T.equalsIgnoreCase(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirective() {
|
||||
return DIRECTIVE_T.equalsIgnoreCase(type);
|
||||
}
|
||||
|
@ -220,7 +226,8 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return matcher.matches();
|
||||
}
|
||||
|
||||
public int getSize(ConfigFieldImpl next) {
|
||||
@Override
|
||||
public int getSize(ConfigField next) {
|
||||
if (isBit() && next.isBit()) {
|
||||
// we have a protection from 33+ bits in a row in BitState, see BitState.TooManyBitsInARow
|
||||
return 0;
|
||||
|
@ -243,10 +250,12 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getArraySizes() {
|
||||
return arraySizes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
if (comment == null)
|
||||
return null;
|
||||
|
@ -258,6 +267,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
*
|
||||
* @see JavaFieldsConsumer#writeJavaFields prefix parameter for structure name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -265,10 +275,12 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
/**
|
||||
* @see com.rusefi.newparse.parsing.Type
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementSize() {
|
||||
return isVoid() ? 0 : TypesHelper.getElementSize(state, type);
|
||||
}
|
||||
|
@ -276,26 +288,32 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
/**
|
||||
* this property of array expands field into a bunch of variables like field1 field2 field3 etc
|
||||
*/
|
||||
@Override
|
||||
public boolean isIterate() {
|
||||
return isIterate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHasAutoscale() {
|
||||
return hasAutoscale;
|
||||
}
|
||||
|
||||
public ReaderStateImpl getState() {
|
||||
@Override
|
||||
public ReaderState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTsInfo() {
|
||||
return tsInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFsioVisible() {
|
||||
return fsioVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String autoscaleSpec() {
|
||||
Pair<Integer, Integer> pair = autoscaleSpecPair();
|
||||
if (pair == null)
|
||||
|
@ -303,6 +321,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return pair.first + ", " + pair.second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double autoscaleSpecNumber() {
|
||||
Pair<Integer, Integer> pair = autoscaleSpecPair();
|
||||
if (pair == null)
|
||||
|
@ -310,6 +329,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return 1.0 * pair.second / pair.first;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Integer, Integer> autoscaleSpecPair() {
|
||||
if (!hasAutoscale) {
|
||||
return null;
|
||||
|
@ -351,12 +371,14 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return new Pair<>(mul, div);
|
||||
}
|
||||
|
||||
private String[] getTokens() {
|
||||
@Override
|
||||
public String[] getTokens() {
|
||||
if (tsInfo == null)
|
||||
return new String[0];
|
||||
return tsInfo.split(",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnits() {
|
||||
String[] tokens = getTokens();
|
||||
if (tokens.length == 0)
|
||||
|
@ -364,6 +386,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return unquote(tokens[0].trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMin() {
|
||||
String[] tokens = getTokens();
|
||||
if (tokens.length < 4)
|
||||
|
@ -371,6 +394,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return Double.parseDouble(tokens[3]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMax() {
|
||||
String[] tokens = getTokens();
|
||||
if (tokens.length < 5)
|
||||
|
@ -378,6 +402,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return Double.parseDouble(tokens[4]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDigits() {
|
||||
String[] tokens = getTokens();
|
||||
if (tokens.length < 6)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.output.ConfigStructure;
|
||||
import com.rusefi.output.ConfigurationConsumer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -23,6 +24,10 @@ public interface ReaderState {
|
|||
|
||||
VariableRegistry getVariableRegistry();
|
||||
|
||||
Map<String, Integer> getTsCustomSize();
|
||||
|
||||
Map<String, ? extends ConfigStructure> getStructures();
|
||||
|
||||
Map<String, String> getTsCustomLine();
|
||||
|
||||
void setHeaderMessage(String headerMessage);
|
||||
|
|
|
@ -386,10 +386,12 @@ public class ReaderStateImpl implements ReaderState {
|
|||
return variableRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getTsCustomSize() {
|
||||
return tsCustomSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends ConfigStructure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.BitState;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderStateImpl;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -33,7 +30,7 @@ public class ConfigStructureImpl implements ConfigStructure {
|
|||
|
||||
private final BitState readingBitState = new BitState();
|
||||
|
||||
private ConfigFieldImpl cPrevField = ConfigFieldImpl.VOID;
|
||||
private ConfigField cPrevField = ConfigFieldImpl.VOID;
|
||||
private final Set<String> names = new HashSet<>();
|
||||
|
||||
public ConfigStructureImpl(String name, String comment, boolean withPrefix) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.BitState;
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -12,7 +13,7 @@ import java.util.List;
|
|||
public class FieldIterator {
|
||||
private final List<ConfigFieldImpl> fields;
|
||||
BitState bitState = new BitState();
|
||||
private ConfigFieldImpl prev = ConfigFieldImpl.VOID;
|
||||
private ConfigField prev = ConfigFieldImpl.VOID;
|
||||
ConfigFieldImpl next;
|
||||
ConfigFieldImpl cf;
|
||||
|
||||
|
@ -23,7 +24,7 @@ public class FieldIterator {
|
|||
/**
|
||||
* return previous field which is not a directive
|
||||
*/
|
||||
public ConfigFieldImpl getPrev() {
|
||||
public ConfigField getPrev() {
|
||||
return prev;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isStringField(ConfigFieldImpl configField) {
|
||||
private boolean isStringField(ConfigField configField) {
|
||||
String custom = state.getTsCustomLine().get(configField.getType());
|
||||
return custom != null && custom.toLowerCase().startsWith(IniFileModel.FIELD_TYPE_STRING);
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
protected int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
|
||||
ConfigFieldImpl prev = iterator.getPrev();
|
||||
ConfigFieldImpl configField = iterator.cf;
|
||||
ConfigFieldImpl next = iterator.next;
|
||||
ConfigField prev = iterator.getPrev();
|
||||
ConfigField configField = iterator.cf;
|
||||
ConfigField next = iterator.next;
|
||||
int bitIndex = iterator.bitState.get();
|
||||
|
||||
if (configField.isDirective())
|
||||
|
|
Loading…
Reference in New Issue