Skip to content

Commit

Permalink
resolved toString code duplication problem
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflow80 committed Dec 1, 2023
1 parent d66bc0a commit 7deaef3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ public String calculateSeqColLevelOneMapDigest(Map<String, String> seqColLevelOn
private String convertSeqColLevelTwoAttributeValuesToString(List<?> seqColL2Attribute, SeqColExtendedDataEntity.AttributeType type) {
switch (type) {
case lengths: // List<Integer> type
return JSONIntegerListExtData.toString((List<Integer>) seqColL2Attribute);
return new JSONIntegerListExtData((List<Integer>) seqColL2Attribute).toString();
default: // List<String> types
return JSONStringListExtData.toString((List<String>) seqColL2Attribute);
return new JSONStringListExtData((List<String>) seqColL2Attribute).toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ public JSONIntegerListExtData(List<Integer> object) {
super(object);
}

/**
* The same as the Overridden toString method
* // TODO: we can get rid of this method for List<Integer> types*/
public static String toString(List<Integer> object) {
return object.toString();
}

@Override
public String toString() {
return this.object.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ public JSONStringListExtData(List<String> object) {
super(object);
}

/**
* The same as the Overridden toString method
* Used to avoid code duplication in different classes
* // TODO: We can find a better way to avoid code duplication*/
public static String toString(List<String> object) {
StringBuilder objectStr = new StringBuilder();
int arraySize = ((List<?>) object).size();
// Include quotes. Eg: ["aaa", "bbb", "ccc"].
objectStr.append("[");
for (int i=0; i<arraySize-1; i++) {
objectStr.append("\"");
objectStr.append(((List<?>) object).get(i));
objectStr.append("\"");
objectStr.append(",");
}
objectStr.append("\"");
objectStr.append(((List<?>) object).get(arraySize-1));
objectStr.append("\"");
objectStr.append("]");

return objectStr.toString();
}

@Override
public String toString() {
StringBuilder objectStr = new StringBuilder();
Expand Down

0 comments on commit 7deaef3

Please sign in to comment.