Fix AlertWindow crashing and make ComparableVersion more generic

This commit is contained in:
Johannes Frohnmeyer 2021-11-30 21:41:15 +01:00
parent d092ad93b1
commit 8c22da0752
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 11 additions and 10 deletions

View File

@ -44,6 +44,6 @@ public class AlertWindow extends Window {
@Override
public void close() {
super.close();
onCancel.run();
if (onCancel != null) onCancel.run();
}
}

View File

@ -1,20 +1,21 @@
package io.gitlab.jfronny.inceptum.model;
import java.util.ArrayList;
import java.util.List;
public class ComparableVersion implements Comparable<ComparableVersion> {
private final String string;
private final long[] numbers;
private final Long[] numbers;
public ComparableVersion(String string) {
this.string = string;
String[] split = string.split("[.+-]+");
this.numbers = new long[split.length];
for (int i = 0; i < split.length; i++) {
try {
numbers[i] = Long.parseLong(split[i]);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Failed to parse version string.");
}
String[] split = string.split("[^0-9]");
List<Long> numbersList = new ArrayList<>();
for (String s : split) {
if (!s.isEmpty())
numbersList.add(Long.parseLong(s));
}
this.numbers = numbersList.toArray(Long[]::new);
}
@Override