add program
This commit is contained in:
parent
08baedfa24
commit
667c79c1aa
12
java-cli.iml
Normal file
12
java-cli.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
32
src/com/company/Main.java
Normal file
32
src/com/company/Main.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.company;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//supported versions;
|
||||
String latest_version = "1.9.4";
|
||||
String min_version = "1.8.3";
|
||||
|
||||
|
||||
System.out.println("\nMinimum Requred Version: " + min_version + " | Latest Stable Version: " + latest_version + "\n");
|
||||
|
||||
|
||||
System.out.println("Test Versions ...");
|
||||
Version.result A = Version.check(min_version,latest_version,"1.9.4");
|
||||
Version.result B = Version.check(min_version,latest_version,"1.10.0+dev-414-gf1fdd782d");
|
||||
Version.result C = Version.check(min_version,latest_version,"no-version-at-all");
|
||||
Version.result D = Version.check(min_version,latest_version,"1.8.1");
|
||||
Version.result E = Version.check(min_version,latest_version,"1.10.0");
|
||||
|
||||
System.out.println("1.9.4 = " + A.name());
|
||||
System.out.println("1.10.0+dev-414-gf1fdd782d = " + B.name());
|
||||
System.out.println("-no-version-at-all- = " + C.name());
|
||||
System.out.println("1.8.1 = " + D.name());
|
||||
System.out.println("1.10.0 = " + E.name());
|
||||
|
||||
System.out.println("...");
|
||||
|
||||
|
||||
}
|
||||
}
|
100
src/com/company/Version.java
Normal file
100
src/com/company/Version.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.company;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Version {
|
||||
public enum result{
|
||||
UNKNOWN,
|
||||
SUPPORTED_LATEST,
|
||||
SUPPORTED_OLD,
|
||||
DEVELOPMENT,
|
||||
UNSUPPORTED_OLD,
|
||||
UNSUPPORTED_NEW
|
||||
}
|
||||
|
||||
|
||||
public static result check(String min, String last, String value) {
|
||||
|
||||
final Pattern pattern_stable_release = Pattern.compile("^(\\d)\\.(\\d+)\\.(\\d+)$");
|
||||
final Pattern pattern_dev_release = Pattern.compile("^(\\d).(\\d+).(\\d+)(\\D)(.+)");
|
||||
Matcher m ;
|
||||
|
||||
m = pattern_stable_release.matcher(value);
|
||||
if (m.find()) {
|
||||
|
||||
switch (correlate(min, last, m.group())){
|
||||
case 0:
|
||||
return result.UNSUPPORTED_OLD;
|
||||
case 1:
|
||||
return result.SUPPORTED_OLD;
|
||||
case 2:
|
||||
return result.SUPPORTED_LATEST;
|
||||
default:
|
||||
return result.UNSUPPORTED_NEW;
|
||||
}
|
||||
|
||||
}
|
||||
m = pattern_dev_release.matcher(value);
|
||||
if (m.find()) {
|
||||
|
||||
m = Pattern.compile("^(\\d)\\.(\\d+)\\.(\\d+)").matcher(value);
|
||||
m.find();
|
||||
|
||||
if (correlate(min, last, m.group())>0) {
|
||||
return result.DEVELOPMENT;
|
||||
} else {
|
||||
return result.UNSUPPORTED_OLD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result.UNKNOWN;
|
||||
|
||||
}
|
||||
|
||||
//helper
|
||||
// 0 to less
|
||||
// 1 in spectrum
|
||||
// 2 at the top
|
||||
// 3 above
|
||||
private static int correlate(String min, String last, String value){
|
||||
//init
|
||||
int i_min = 0, i_last = 0, i_value = 0;
|
||||
|
||||
while (value.indexOf(".")>0) {
|
||||
|
||||
//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(".")));
|
||||
|
||||
|
||||
if ( i_min != i_last ) {
|
||||
//check
|
||||
if (i_value < i_min) return 0;
|
||||
if (i_value > i_last) return 3;
|
||||
}
|
||||
|
||||
//prepare for next checks
|
||||
if (min.indexOf(".") < 0) return 0;
|
||||
|
||||
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);
|
||||
|
||||
if (i_value < i_min) return 0;
|
||||
if (i_min < i_value && i_value < i_last) return 1;
|
||||
if (i_value == i_last) return 2;
|
||||
if (i_value > i_last) return 3;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user