use compare func for range test

This commit is contained in:
6543 2019-10-20 22:17:00 +02:00
parent b030d45f93
commit cab7b33ca5
Signed by: 6543
GPG Key ID: A1CA74D27FD13271

View File

@ -68,53 +68,29 @@ public enum Version {
// 2 at the top // 2 at the top
// 3 above // 3 above
private static int correlate(String min, String last, String value){ private static int correlate(String min, String last, String value){
//init int min_check = compare(value,min);
int i_min = 0, i_last = 0, i_value = 0; int max_check = compare(value,last);
int range_check = compare(min,last);


//go down each integer (separated by points) until it is the last one switch (range_check) {
while (value.contains(".")) { case 2:

throw new Error("Minimum Version higher than Last Version");
//prepare for checks case 1: //min == last
i_min = Integer.parseInt(min.substring(0,min.indexOf("."))); switch (min_check) {
i_last = Integer.parseInt(last.substring(0,last.indexOf(".")));
i_value = Integer.parseInt(value.substring(0,value.indexOf(".")));

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: case 0:
return 0; return 0;
case 1: case 1:
return 1; return 2;
case 2: default:
if (i_value < i_last ) return 1;
if (i_value == i_last) return 2;
case 3:
return 3; return 3;
} }
} else { //value in range default:
if (max_check >1) return 3;
if (max_check == 1) return 2;
if (min_check < 1) return 0;
return 1; return 1;
}
} }


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

//check last integer
if (i_min > i_last){
if (i_value == i_last) return 2;
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;
} }


/** /**