update function

This commit is contained in:
6543 2019-10-20 21:58:29 +02:00
parent 42678a3984
commit 1630d47f9c
Signed by: 6543
GPG Key ID: A1CA74D27FD13271

View File

@ -25,6 +25,10 @@ public enum Version {
final Pattern pattern_dev_release = Pattern.compile("^(\\d).(\\d+).(\\d+)(\\D)(.+)");
Matcher m ;

if (!pattern_stable_release.matcher(min).find() || !pattern_stable_release.matcher(last).find()) {
throw new Error("VersionCheck: wrong format for min or last version given");
}

m = pattern_stable_release.matcher(value);
if (m.find()) {

@ -60,7 +64,7 @@ public enum Version {

//helper
// 0 to less
// 1 in spectrum
// 1 in range
// 2 at the top
// 3 above
private static int correlate(String min, String last, String value){
@ -68,35 +72,50 @@ public enum Version {
int i_min = 0, i_last = 0, i_value = 0;

//go down each integer (separated by points) until it is the last one
while (value.indexOf(".")>0) {
while (value.contains(".")) {

//prepare for checks
if (min.indexOf(".") >= 0) i_min = Integer.valueOf(min.substring(0,min.indexOf(".")));
if (last.indexOf(".") >= 0) i_last = Integer.valueOf(last.substring(0,last.indexOf(".")));
if (value.indexOf(".") >= 0) i_value = Integer.valueOf(value.substring(0,value.indexOf(".")));
i_min = Integer.parseInt(min.substring(0,min.indexOf(".")));
i_last = Integer.parseInt(last.substring(0,last.indexOf(".")));
i_value = Integer.parseInt(value.substring(0,value.indexOf(".")));

if ( i_min != i_last ) {
//check
if (i_value < i_min) return 0;
if (i_value > i_last) return 3;

//check in range correlation
int result = correlate(min.substring(min.indexOf(".")+1),last.substring(last.indexOf(".")+1),value.substring(value.indexOf(".")+1));

if (i_value == i_last) {
switch (result){
case 0:
return 0;
case 1:
return 1;
case 2:
if (i_value < i_last ) return 1;
if (i_value == i_last) return 2;
case 3:
return 3;
}
} else { //value in range
return 1;
}
}

//delete checked integer and move on to next one
min = min.substring(min.indexOf(".")+1);
last = last.substring(last.indexOf(".")+1);
value = value.substring(value.indexOf(".")+1);

}

i_min = Integer.valueOf(min);
i_last = Integer.valueOf(last);
i_value = Integer.valueOf(value);
i_min = Integer.parseInt(min);
i_last = Integer.parseInt(last);
i_value = Integer.parseInt(value);

//check last integer
if (i_value < i_min) return 0;
if (i_min < i_value && i_value < i_last) return 1;
if (i_min > i_last){
if (i_value == i_last) return 2;
if (i_value > i_last) return 3;
if (i_value < i_last) return 1;
}
if (i_value < i_min) return 0;
if (i_value >= i_min && i_value < i_last) return 1;
if (i_value == i_last) return 2;
return 3;
}


return 0;