diff options
-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 |