| Summary: | Values of Storage Type are not correctly sorted | ||
|---|---|---|---|
| Product: | Group17 | Reporter: | kinluntam2-c |
| Component: | Component Sorter | Assignee: | wdwong3-c |
| Status: | RESOLVED FIXED | ||
| Severity: | minor | ||
| Priority: | Normal | ||
| Version: | unspecified | ||
| Hardware: | PC | ||
| OS: | Windows | ||
| Attachments: |
The Capture of the Wrongly Sorted Storage List
Fixed bug of wrongly sorted Storage List (Type) |
||
*** Bug 312 has been marked as a duplicate of this bug. *** Created attachment 29 [details]
Fixed bug of wrongly sorted Storage List (Type)
You are right. The bug is caused the data type of Storage.type. It is stored as String but the sorting method is based on int.
To fix this bug, we need to change the custom sorting method in Storage.java. We first split the string into different parts, then parse them into int for comparison. Since there are types not starting with numbers, we add an exception to compare them based on lexicographical order.
The code below fixes the bug:
public static Comparator<Storage> typeComparator = new Comparator<Storage>() {
@Override
public int compare(Storage s1, Storage s2) {
String[] tokens1 = s1.getType().split(" ");
String[] tokens2 = s2.getType().split(" ");
try {
int t1 = Integer.parseInt(tokens1[0]);
int t2 = Integer.parseInt(tokens2[0]);
return (t2 > t1 ? -1 : (t2 == t1 ? 0 : 1));
}
catch(Exception e) {
return (int) (s1.getType().compareTo(s2.getType()));
}
}
};
|
Created attachment 28 [details] The Capture of the Wrongly Sorted Storage List When I click the "Type" column on the Storage List, I found that the values of the storage types are not sorted correctly. The values of "Type" are expected to be sorted by the number (i.e. “10000 RPM” should be put behind “5400 RPM” in ascending order). However, in the actual result, “10000 RPM” will be put before “5400 RPM”. Step to reproduce: 1. Click the Storage List tab 2. Click the column header "Type" to call the sort function in "StorageController" I think the potential result is that the values are sorted as strings, but not numbers. Therefore, it will check the characters in the values one by one for the sort function. (i.e. “1” will be put before “5”)