only:refactoring:extract part of functionality into `formatValue` and `getValues` methods #7476
This commit is contained in:
parent
ded32f30c3
commit
22106d5979
|
@ -46,36 +46,64 @@ public class ArrayIniField extends IniField {
|
||||||
return type.getStorageSize() * cols * rows;
|
return type.getStorageSize() * cols * rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String formatValue(final String[][] values) {
|
||||||
public String getValue(ConfigurationImage image) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
for (final String[] row : values) {
|
||||||
sb.append("\n ");
|
sb.append("\n ");
|
||||||
for (int colIndex = 0; colIndex < cols; colIndex++) {
|
for (final String element : row) {
|
||||||
Field f = new Field(getName() + "_" + colIndex, getOffset(rowIndex, colIndex), getType());
|
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(f.getAnyValue(image, multiplier));
|
sb.append(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue(final ConfigurationImage image) {
|
||||||
|
final String[][] values = new String[rows][cols];
|
||||||
|
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
||||||
|
for (int colIndex = 0; colIndex < cols; colIndex++) {
|
||||||
|
final Field f = new Field(getName() + "_" + colIndex, getOffset(rowIndex, colIndex), getType());
|
||||||
|
values[rowIndex][colIndex] = f.getAnyValue(image, multiplier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return formatValue(values);
|
||||||
|
}
|
||||||
|
|
||||||
private int getOffset(int rowIndex, int colIndex) {
|
private int getOffset(int rowIndex, int colIndex) {
|
||||||
return getOffset() + (rowIndex * cols + colIndex) * getType().getStorageSize();
|
return getOffset() + (rowIndex * cols + colIndex) * getType().getStorageSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[][] getValues(final String value) {
|
||||||
|
final String[] values = value.trim().split("\\s+");
|
||||||
|
if (values.length != rows * cols) {
|
||||||
|
throw new IllegalStateException(values.length + " values while expecting " + getRows() + " by " + getCols() + " total " + rows * cols);
|
||||||
|
} else {
|
||||||
|
final String[][] result = new String[rows][cols];
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
final int rowIndex = i / cols;
|
||||||
|
final int colIndex = i % cols;
|
||||||
|
result[rowIndex][colIndex] = values[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(ConfigurationImage image, Constant constant) {
|
public void setValue(ConfigurationImage image, Constant constant) {
|
||||||
String[] values = constant.getValue().trim().split("\\s+");
|
final String[][] values = getValues(constant.getValue());
|
||||||
if (values.length != getRows() * getCols())
|
for (int rowIndex = 0; rowIndex < values.length; rowIndex++) {
|
||||||
throw new IllegalStateException(values.length + " values while expecting " + getRows() + " by " + getCols() + " total " + getRows() * getCols());
|
final String[] row = values[rowIndex];
|
||||||
|
for (int colIndex = 0; colIndex < row.length; colIndex++) {
|
||||||
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
||||||
for (int colIndex = 0; colIndex < cols; colIndex++) {
|
|
||||||
String value = values[rowIndex * cols + colIndex];
|
|
||||||
ByteBuffer wrapped = image.getByteBuffer(getOffset(rowIndex, colIndex), type.getStorageSize());
|
ByteBuffer wrapped = image.getByteBuffer(getOffset(rowIndex, colIndex), type.getStorageSize());
|
||||||
ScalarIniField.setValue(wrapped, type, value, Field.NO_BIT_OFFSET, multiplier);
|
ScalarIniField.setValue(
|
||||||
|
wrapped,
|
||||||
|
type,
|
||||||
|
values[rowIndex][colIndex],
|
||||||
|
Field.NO_BIT_OFFSET,
|
||||||
|
multiplier
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue