This is a general approach I'd suggest you consider taking considering the nature of your data.
If you don't want to use comparable, you will need to sort based on the "major" version, followed by the "minor" (for each major version), then each "finest" version (for the minor version). That will allow you to deal with the ones that don't have finer levels or those that don't use numbers like your 5.x
Use the '.' as separators to know what portions of your string to use to sort on for each level. You may want to save the results to a map by level (or something along those lines) where you can pull the results from each out and not have deeply nested loops in your code. I would use a RegEx pattern to assist with the coding.
EDIT
In response to comments...
Note: I have not tested the code below, but it does appear that it will compile.
List<String> src = new List<String>{
'7.1.2', '8.1.3', '11.0.5', '5.x', '10.0.89', '12.13.14'};
// declare maps and lists you will need
map<string, string>srcOrderMap = new map<string, string>();
map<string, list<string>>srcOrderLstMap = new map<string, List<string>>();
Integer count = 0;
integer iString = string.valueOf(count);
integer iString=string.valueOf(count);
list<string>b_count = new list<string>();
// create map for where you started from for complete string and list string
for(string s:src){
b_count=b.split('.');
srcOrderMap.put(iString,b_count);
srcOrderMap.put(iString,s);
count++;
}
// declare variables for next loop
map<string, string>srcCol0OrderMap = new map<string, string>();
map<string, string>srcCol1OrderMap = new map<string, string>();
map<string, string>srcCol2OrderMap = new map<string, string>();
list<string>sArrayCol0 = new list<string>();
list<string>sArrayCol1 = new list<string>();
list<string>sArrayCol2 = new list<string>();
// create maps for each column and lists of those values
for(integer s=0;s=srcOrderMap.size();s++){
for(integer c=0;c<3;c++){
if(c == 0){
sArrayCol0.add.srcOrderMap.get(string.valueOf(s)[0]);
}
if(c == 1){
sArrayCol1.add.srcOrderMap.get(string.valueOf(s)[1]);
}
if(c == 2){
sArrayCol2.add.srcOrderMap.get(string.valueOf(s)[2]);
}
srcCol0OrderMap.put(string.valueOf(s), sArrayCol0[string.valueOf(s)]);
srcCol1OrderMap.put(string.valueOf(s), sArrayCol1[string.valueOf(s)]);
srcCol2OrderMap.put(string.valueOf(s), sArrayCol2[string.valueOf(s)]);
}
}
Now you can do a sort on column 0, after which you can do a sub-sort on column1
where any values in column 0 are the same to determine which value gets moved
up or down in your map.
// sort the values in column 0
sArrayCol0.sort();
I'll leave it to you to determine how you want to find the duplicate values in the list. There are lots of solutions to that problem you should be able to find on your own.
Once you have the sorted column 0 results, all you need to do is go back to your original source map and retrieve the original values that are also ready for you in sArrayCol1
where they're ready for you to sort()
and compare. The results of that sort will determine which one of the values in Col 0 "wins". If both are equal, then you sort again on based on the values found in sArrayCol2
as once again are referenced in the original source map.
That's the reason I recommended using maps, so you can keep track of these values and will always be able to go back and reference them from where you began as you re-order your records at different levels. I hope this provides you with the "map" you need to reach your destination.