in codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SemanticVersion.java [272:317]
private static int comparePreRelease(String x, String y) {
String[] xIdentifiers = x.split("\\.");
String[] yIdentifiers = y.split("\\.");
int cmp = 0;
int xPos = 0;
int yPos = 0;
while (xPos < xIdentifiers.length && yPos < yIdentifiers.length && cmp == 0) {
Optional<Integer> xInt = parsePositiveInteger(xIdentifiers[xPos]);
Optional<Integer> yInt = parsePositiveInteger(yIdentifiers[yPos]);
if (xInt.isPresent() && yInt.isPresent()) {
cmp = Integer.compare(xInt.get(), yInt.get());
continue;
}
if (xInt.isPresent()) {
cmp = -1;
continue;
}
if (yInt.isPresent()) {
cmp = 1;
continue;
}
cmp = xIdentifiers[xPos].compareTo(yIdentifiers[yPos]);
xPos++;
yPos++;
}
if (cmp != 0) {
return cmp;
}
int xRemaining = xIdentifiers.length - 1 - xPos;
int yRemaining = yIdentifiers.length - 1 - yPos;
if (xRemaining == yRemaining) {
return 0;
}
return (xRemaining < yRemaining) ? -1 : 1;
}