|
@@ -67,15 +67,50 @@ public class Version implements Comparable<Version> {
|
67
|
67
|
final String myParts[] = this.strVersion.split("-");
|
68
|
68
|
final String thParts[] = o.strVersion.split("-");
|
69
|
69
|
|
70
|
|
- final String myFirstParts[] = myParts[0].split("\\.");
|
71
|
|
- final String thFirstParts[] = thParts[0].split("\\.");
|
|
70
|
+ final String myFirstParts[] = myParts[0].split("\\.|(?=a|b|rc|m)");
|
|
71
|
+ final String thFirstParts[] = thParts[0].split("\\.|(?=a|b|rc|m)");
|
72
|
72
|
|
73
|
73
|
for (int i = 0; i < Math.max(myFirstParts.length, thFirstParts.length); i++) {
|
74
|
|
- final int myInt = myFirstParts.length > i ? Integer.parseInt(myFirstParts[i]) : 0;
|
75
|
|
- final int thInt = thFirstParts.length > i ? Integer.parseInt(thFirstParts[i]) : 0;
|
|
74
|
+ final boolean myExists = myFirstParts.length > i;
|
|
75
|
+ final boolean thExists = thFirstParts.length > i;
|
76
|
76
|
|
77
|
|
- if (myInt != thInt) {
|
|
77
|
+ final boolean myIsInt = myExists && myFirstParts[i].matches("[0-9]+");
|
|
78
|
+ final boolean thIsInt = thExists && thFirstParts[i].matches("[0-9]+");
|
|
79
|
+
|
|
80
|
+ final int myInt = myIsInt ? Integer.parseInt(myFirstParts[i]) : 0;
|
|
81
|
+ final int thInt = thIsInt ? Integer.parseInt(thFirstParts[i]) : 0;
|
|
82
|
+
|
|
83
|
+ // Please consult handwritten truth table in the care of
|
|
84
|
+ // Chris for an explanation of what the hell is going on here.
|
|
85
|
+ // If there's a bug in this code it should probably be
|
|
86
|
+ // rewritten.
|
|
87
|
+ if ((!myExists && !thExists)
|
|
88
|
+ || (myIsInt && thIsInt && myInt == thInt)
|
|
89
|
+ || (myExists && thExists && !myIsInt && !thIsInt
|
|
90
|
+ && myFirstParts[i].equals(thFirstParts[i]))) {
|
|
91
|
+ continue;
|
|
92
|
+ } else if ((!thExists && myIsInt)
|
|
93
|
+ || (thExists && !thIsInt && (!myExists || myIsInt))) {
|
|
94
|
+ return +1;
|
|
95
|
+ } else if ((thIsInt && !myExists)
|
|
96
|
+ || (myExists && !myIsInt && (!thExists || thIsInt))) {
|
|
97
|
+ return -1;
|
|
98
|
+ } else if (thIsInt && myIsInt) {
|
78
|
99
|
return myInt - thInt;
|
|
100
|
+ } else {
|
|
101
|
+ final String myLetterParts[] = myFirstParts[i].split("(?=[0-9])", 2);
|
|
102
|
+ final String thLetterParts[] = thFirstParts[i].split("(?=[0-9])", 2);
|
|
103
|
+
|
|
104
|
+ if (myLetterParts[0].equals(thLetterParts[0])) {
|
|
105
|
+ return Integer.parseInt(myLetterParts[1])
|
|
106
|
+ - Integer.parseInt(thLetterParts[1]);
|
|
107
|
+ } else if (myLetterParts[0].equals("m")
|
|
108
|
+ || thLetterParts[0].equals("rc")
|
|
109
|
+ || (myLetterParts[0].equals("a") && thLetterParts[0].equals("b"))) {
|
|
110
|
+ return -1;
|
|
111
|
+ } else {
|
|
112
|
+ return +1;
|
|
113
|
+ }
|
79
|
114
|
}
|
80
|
115
|
}
|
81
|
116
|
|