change class to enum

This commit is contained in:
6543 2019-10-13 15:12:48 +02:00
parent 2446c8aafa
commit 8dbe12bfb2
Signed by: 6543
GPG Key ID: A1CA74D27FD13271
4 changed files with 31 additions and 22 deletions

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -13,11 +13,11 @@ public class Main {
System.out.println("Test Versions ..."); System.out.println("Test Versions ...");
Version.result A = Version.check(min_version,latest_version,"1.9.4"); Version 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 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 C = Version.check(min_version,latest_version,"no-version-at-all");
Version.result D = Version.check(min_version,latest_version,"1.8.1"); Version D = Version.check(min_version,latest_version,"1.8.1");
Version.result E = Version.check(min_version,latest_version,"1.10.0"); Version E = Version.check(min_version,latest_version,"1.10.0");


System.out.println("1.9.4 = " + A.name()); System.out.println("1.9.4 = " + A.name());
System.out.println("1.10.0+dev-414-gf1fdd782d = " + B.name()); System.out.println("1.10.0+dev-414-gf1fdd782d = " + B.name());

View File

@ -3,18 +3,17 @@ package com.company;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;


public class Version { public enum Version {
public enum result{ UNKNOWN,
UNKNOWN, SUPPORTED_LATEST,
SUPPORTED_LATEST, SUPPORTED_OLD,
SUPPORTED_OLD, DEVELOPMENT,
DEVELOPMENT, UNSUPPORTED_OLD,
UNSUPPORTED_OLD, UNSUPPORTED_NEW;
UNSUPPORTED_NEW
}




public static result check(String min, String last, String value) {
public static Version check(String min, String last, String value) {


final Pattern pattern_stable_release = Pattern.compile("^(\\d)\\.(\\d+)\\.(\\d+)$"); final Pattern pattern_stable_release = Pattern.compile("^(\\d)\\.(\\d+)\\.(\\d+)$");
final Pattern pattern_dev_release = Pattern.compile("^(\\d).(\\d+).(\\d+)(\\D)(.+)"); final Pattern pattern_dev_release = Pattern.compile("^(\\d).(\\d+).(\\d+)(\\D)(.+)");
@ -25,13 +24,13 @@ public class Version {


switch (correlate(min, last, m.group())){ switch (correlate(min, last, m.group())){
case 0: case 0:
return result.UNSUPPORTED_OLD; return UNSUPPORTED_OLD;
case 1: case 1:
return result.SUPPORTED_OLD; return SUPPORTED_OLD;
case 2: case 2:
return result.SUPPORTED_LATEST; return SUPPORTED_LATEST;
default: default:
return result.UNSUPPORTED_NEW; return UNSUPPORTED_NEW;
} }


} }
@ -42,14 +41,14 @@ public class Version {
m.find(); m.find();


if (correlate(min, last, m.group())>0) { if (correlate(min, last, m.group())>0) {
return result.DEVELOPMENT; return DEVELOPMENT;
} else { } else {
return result.UNSUPPORTED_OLD; return UNSUPPORTED_OLD;
} }


} }


return result.UNKNOWN; return UNKNOWN;


} }



4
src/com/company/tst.java Normal file
View File

@ -0,0 +1,4 @@
package com.company;

public enum tst {
}