Skip to content

Commit

Permalink
Refacturing in SDR serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardofroes committed Aug 15, 2022
1 parent de2cff6 commit f5dd3b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.github.CST-Group'
version '0.1.8'
version '0.1.9'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -59,7 +59,7 @@ publishing {
gpr(MavenPublication) {
groupId = 'com.github.CST-Group'
artifactId = 'ctm'
version = '0.1.8'
version = '0.1.9'

from(components.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public SDRIdea serialize(Idea idea) throws Exception {
SDRIdea sdrIdea = new SDRIdeaBuilder().build(channels, rows, columns, getDefaultValue(),
getActiveValue());

setIdValue(idea, sdrIdea, sdrIdea.getSdr(), 0);
setIdValue(idea, sdrIdea.getSdr(), 0);
setNameValue(idea, sdrIdea, sdrIdea.getSdr(), 0);
setTypeValue(idea, sdrIdea, sdrIdea.getSdr(), 0);
setMetadataValue(idea, sdrIdea, sdrIdea.getSdr(), 0);
valueAnalyse(idea, sdrIdea, sdrIdea.getSdr(), 0);
setMetadataValue(idea, sdrIdea.getSdr(), 0);
valueAnalyse(idea, sdrIdea.getSdr(), 0);

generateSDR(sdrIdea, idea);

Expand All @@ -77,26 +77,26 @@ public SDRIdea serialize(Idea idea) throws Exception {
}
}

private void setParentValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel) {
setNumericValue(sdrIdea, sdr, channel, 0, columns, (int)idea.getId());
private void setParentValue(Idea idea, int[][][] sdr, int channel) {
setNumericValue(sdr, channel, 0, columns, (int)idea.getId());
}

private void setIdValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel) {
setNumericValue(sdrIdea, sdr, channel, 2, columns, (int)idea.getId());
private void setIdValue(Idea idea, int[][][] sdr, int channel) {
setNumericValue(sdr, channel, 2, columns, (int)idea.getId());
}

private void valueAnalyse(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel) {
private void valueAnalyse(Idea idea, int[][][] sdr, int channel) {
if (ValueValidation.isArray(idea.getValue())) {
List values = valueConverter.convertToList(idea.getValue());
for (int i = 0; i < values.size(); i++) {
setNumericValue(sdrIdea, sdr, channel, 11+i*2, columns, (Number)values.get(i));
setNumericValue(sdr, channel, 11+i*2, columns, (Number)values.get(i));
}
} else {
if (ValueValidation.isPrimitive(idea.getValue())) {
if(idea.getValue().getClass().equals(Boolean.class)) {
setValue(sdr, channel, 11, getArrayFromDictionary((String) idea.getValue()));
} else {
setNumericValue(sdrIdea, sdr, channel, 11, columns, (Number)idea.getValue());
setNumericValue(sdr, channel, 11, columns, (Number)idea.getValue());
}
} else if (ValueValidation.isString(idea.getValue())) {
if (idea.getValue() != null) {
Expand All @@ -110,24 +110,24 @@ public void generateSDR(SDRIdea sdrIdea, Idea idea) {

for (Idea childIdea : idea.getL()) {

setParentValue(idea, sdrIdea, sdrIdea.getSdr(), channelCounter);
setIdValue(childIdea, sdrIdea, sdrIdea.getSdr(), channelCounter);
setParentValue(idea, sdrIdea.getSdr(), channelCounter);
setIdValue(childIdea, sdrIdea.getSdr(), channelCounter);
setNameValue(childIdea, sdrIdea, sdrIdea.getSdr(), channelCounter);
setTypeValue(childIdea, sdrIdea, sdrIdea.getSdr(), channelCounter);
setMetadataValue(childIdea, sdrIdea, sdrIdea.getSdr(), channelCounter);
valueAnalyse(childIdea, sdrIdea, sdrIdea.getSdr(), channelCounter);
setMetadataValue(childIdea, sdrIdea.getSdr(), channelCounter);
valueAnalyse(childIdea, sdrIdea.getSdr(), channelCounter);

channelCounter++;
generateSDR(sdrIdea, childIdea);
}
}

private void setMetadataValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel) {
private void setMetadataValue(Idea idea, int[][][] sdr, int channel) {
if (idea.getValue() != null) {
Integer metadataValue = IdeaMetadataValues.getMetadataMap()
.get(idea.getValue().getClass());

setNumericValue(sdrIdea, sdr, channel, 7, columns, metadataValue);
setNumericValue(sdr, channel, 7, columns, metadataValue);

int length = 0;

Expand All @@ -136,7 +136,7 @@ private void setMetadataValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int cha
length = values.size();
}

setNumericValue(sdrIdea, sdr, channel, 9, columns, length);
setNumericValue(sdr, channel, 9, columns, length);
}
}

Expand All @@ -147,14 +147,14 @@ private void setNameValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel
}

private void setTypeValue(Idea idea, SDRIdea sdrIdea, int[][][] sdr, int channel) {
setNumericValue(sdrIdea, sdr, channel, 5, columns, (int)idea.getType());
setNumericValue(sdr, channel, 5, columns, (int)idea.getType());
}

private void setValue(int[][][] sdr, int channel, int row, int[] value) {
sdr[channel][row] = value;
}

private void setNumericValue(SDRIdea sdrIdea, int[][][] sdr, int channel, int row, int length, Number value) {
private void setNumericValue(int[][][] sdr, int channel, int row, int length, Number value) {
int range = length/4;

List<Double> baseTenValue = valueConverter.convertNumberToBaseTen(value.doubleValue());
Expand Down

0 comments on commit f5dd3b3

Please sign in to comment.