diff options
author | Decheng Zhang <decheng.zhang@huawei.com> | 2021-02-16 10:22:08 -0500 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-02-22 20:35:48 +0000 |
commit | 374e6dac622a0faf22475d4bc959086a917dbe99 (patch) | |
tree | 815802bbe44385702774d53b03e1a6f423a67c4f /core | |
parent | 103495d08e2f69f2d63389695f3d2a0d4a69630e (diff) |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java | 51 |
1 files changed, 50 insertions, 1 deletions
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 98cf7e05e..e786cff43 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 @@ public class SvcLogicContext { 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 |