Fix designation sorting of various Cesaroni motors
This commit is contained in:
parent
ff83f2bad8
commit
4141b478f7
@ -19,9 +19,25 @@ public class DesignationComparator implements Comparator<String> {
|
|||||||
COLLATOR = Collator.getInstance(Locale.US);
|
COLLATOR = Collator.getInstance(Locale.US);
|
||||||
COLLATOR.setStrength(Collator.PRIMARY);
|
COLLATOR.setStrength(Collator.PRIMARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pattern pattern =
|
/*
|
||||||
Pattern.compile("^([0-9][0-9]+|1/([1-8]))?([a-zA-Z])([0-9]+)(.*?)$");
|
* Regexp to parse the multitude of designations. Supported types:
|
||||||
|
*
|
||||||
|
* 1/4A4...
|
||||||
|
* 1/2A4...
|
||||||
|
* A4...
|
||||||
|
* 132G100...
|
||||||
|
* 132-G100...
|
||||||
|
*
|
||||||
|
* Capture groups:
|
||||||
|
* 1 = garbage (stuff before impulse class)
|
||||||
|
* 2 = divisor number for 1/2A, 1/4A etc, otherwise null
|
||||||
|
* 3 = impulse class letter
|
||||||
|
* 4 = average thrust
|
||||||
|
* 5 = stuff after thrust number
|
||||||
|
*/
|
||||||
|
private Pattern pattern =
|
||||||
|
Pattern.compile("^([0-9]+-?|1/([1-8]))?([a-zA-Z])([0-9,]+)(.*?)$");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(String o1, String o2) {
|
public int compare(String o1, String o2) {
|
||||||
@ -32,13 +48,13 @@ public class DesignationComparator implements Comparator<String> {
|
|||||||
m2 = pattern.matcher(o2);
|
m2 = pattern.matcher(o2);
|
||||||
|
|
||||||
if (m1.find() && m2.find()) {
|
if (m1.find() && m2.find()) {
|
||||||
|
|
||||||
String o1Class = m1.group(3);
|
String o1Class = m1.group(3);
|
||||||
int o1Thrust = Integer.parseInt(m1.group(4));
|
int o1Thrust = Integer.parseInt(m1.group(4).replaceAll(",", ""));
|
||||||
String o1Extra = m1.group(5);
|
String o1Extra = m1.group(5);
|
||||||
|
|
||||||
String o2Class = m2.group(3);
|
String o2Class = m2.group(3);
|
||||||
int o2Thrust = Integer.parseInt(m2.group(4));
|
int o2Thrust = Integer.parseInt(m2.group(4).replaceAll(",", ""));
|
||||||
String o2Extra = m2.group(5);
|
String o2Extra = m2.group(5);
|
||||||
|
|
||||||
// 1. Motor class
|
// 1. Motor class
|
||||||
@ -46,18 +62,18 @@ public class DesignationComparator implements Comparator<String> {
|
|||||||
// 1/2A and 1/4A comparison
|
// 1/2A and 1/4A comparison
|
||||||
String sub1 = m1.group(2);
|
String sub1 = m1.group(2);
|
||||||
String sub2 = m2.group(2);
|
String sub2 = m2.group(2);
|
||||||
|
|
||||||
if (sub1 != null || sub2 != null) {
|
if (sub1 != null || sub2 != null) {
|
||||||
if (sub1 == null)
|
if (sub1 == null)
|
||||||
sub1 = "1";
|
sub1 = "1";
|
||||||
if (sub2 == null)
|
if (sub2 == null)
|
||||||
sub2 = "1";
|
sub2 = "1";
|
||||||
value = -COLLATOR.compare(sub1,sub2);
|
value = -COLLATOR.compare(sub1, sub2);
|
||||||
if (value != 0)
|
if (value != 0)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = COLLATOR.compare(o1Class,o2Class);
|
value = COLLATOR.compare(o1Class, o2Class);
|
||||||
if (value != 0)
|
if (value != 0)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user