Fix CCSDK-3168, issue that toJsonString doesn't work properly for large array attributes.
Issue-Id: CCSDK-3168
Signed-off-by: Decheng Zhang <decheng.zhang@huawei.com>
Change-Id: I0aba52ea194dfe52db09a19da2f67d03619bb912
Signed-off-by: Decheng Zhang <decheng.zhang@huawei.com>
diff --git a/core/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/core/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
index 98cf7e0..e786cff 100644
--- a/core/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
+++ b/core/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
@@ -314,7 +314,56 @@
String attrVal = null;
// Sort properties so that arrays will be reconstructed in proper order
- TreeMap<String, String> sortedAttributes = new TreeMap<>();
+ TreeMap<String, String> sortedAttributes = new TreeMap<>(new Comparator<String>(
+ ) {
+ @Override
+ public int compare(String a, String b){
+ int aLength = a.length();
+ int bLength = b.length();
+ int minSize = Math.min(aLength, bLength);
+ char aChar, bChar;
+ boolean aNumber, bNumber;
+ boolean asNumeric = false;
+ int lastNumericCompare = 0;
+ for (int i = 0; i < minSize; i++) {
+ aChar = a.charAt(i);
+ bChar = b.charAt(i);
+ aNumber = aChar >= '0' && aChar <= '9';
+ bNumber = bChar >= '0' && bChar <= '9';
+ if (asNumeric)
+ if (aNumber && bNumber) {
+ if (lastNumericCompare == 0)
+ lastNumericCompare = aChar - bChar;
+ } else if (aNumber)
+ return 1;
+ else if (bNumber)
+ return -1;
+ else if (lastNumericCompare == 0) {
+ if (aChar != bChar)
+ return aChar - bChar;
+ asNumeric = false;
+ } else
+ return lastNumericCompare;
+ else if (aNumber && bNumber) {
+ asNumeric = true;
+ if (lastNumericCompare == 0)
+ lastNumericCompare = aChar - bChar;
+ } else if (aChar != bChar)
+ return aChar - bChar;
+ }
+ if (asNumeric)
+ if (aLength > bLength && a.charAt(bLength) >= '0' && a.charAt(bLength) <= '9') // as number
+ return 1; // a has bigger size, thus b is smaller
+ else if (bLength > aLength && b.charAt(aLength) >= '0' && b.charAt(aLength) <= '9') // as number
+ return -1; // b has bigger size, thus a is smaller
+ else if (lastNumericCompare == 0)
+ return aLength - bLength;
+ else
+ return lastNumericCompare;
+ else
+ return aLength - bLength;
+ }
+ });
sortedAttributes.putAll(attributes);
// Loop through properties, sorted by key