Launcher/libLauncher/src/main/java/ru/gravit/utils/Version.java

118 lines
2.7 KiB
Java
Raw Normal View History

package ru.gravit.utils;
2018-09-17 10:07:32 +03:00
import ru.gravit.launcher.LauncherAPI;
2018-09-17 10:07:32 +03:00
2018-12-20 18:45:01 +03:00
import java.util.Objects;
2019-01-08 16:36:05 +03:00
public final class Version {
@LauncherAPI
2018-09-17 10:07:32 +03:00
public final int major;
@LauncherAPI
2018-09-17 10:07:32 +03:00
public final int minor;
@LauncherAPI
2018-09-17 10:07:32 +03:00
public final int patch;
@LauncherAPI
2018-09-17 10:07:32 +03:00
public final int build;
@LauncherAPI
2018-09-17 10:07:32 +03:00
public final Type release;
2018-09-22 17:33:00 +03:00
@LauncherAPI
public Version(int major, int minor, int patch) {
2018-09-17 10:07:32 +03:00
this.major = major;
this.minor = minor;
this.patch = patch;
build = 0;
release = Type.UNKNOWN;
}
2018-09-22 17:33:00 +03:00
@LauncherAPI
public Version(int major, int minor, int patch, int build) {
2018-09-17 10:07:32 +03:00
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
release = Type.UNKNOWN;
}
2018-09-22 17:33:00 +03:00
@LauncherAPI
public Version(int major, int minor, int patch, int build, Type release) {
2018-09-17 10:07:32 +03:00
this.major = major;
this.minor = minor;
this.patch = patch;
this.build = build;
this.release = release;
}
@Override
@LauncherAPI
2018-09-17 10:07:32 +03:00
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Version that = (Version) o;
2018-09-17 10:07:32 +03:00
return major == that.major &&
minor == that.minor &&
patch == that.patch &&
build == that.build;
}
2018-09-22 17:33:00 +03:00
@LauncherAPI
2018-09-17 10:07:32 +03:00
public String getVersionString() {
2018-09-22 17:33:00 +03:00
return String.format("%d.%d.%d", major, minor, patch);
2018-09-17 10:07:32 +03:00
}
@Override
@LauncherAPI
2018-09-17 10:07:32 +03:00
public int hashCode() {
return Objects.hash(major, minor, patch, build);
}
2018-09-22 17:33:00 +03:00
@LauncherAPI
2018-09-22 17:33:00 +03:00
public String getReleaseStatus() {
2018-09-17 10:07:32 +03:00
String result;
switch (release) {
case LTS:
2018-09-22 17:33:00 +03:00
result = "lts";
2018-09-17 10:07:32 +03:00
break;
case STABLE:
2018-09-22 17:33:00 +03:00
result = "stable";
2018-09-17 10:07:32 +03:00
break;
case BETA:
2018-09-22 17:33:00 +03:00
result = "beta";
2018-09-17 10:07:32 +03:00
break;
case ALPHA:
2018-09-22 17:33:00 +03:00
result = "alpha";
2018-09-17 10:07:32 +03:00
break;
case DEV:
2018-09-22 17:33:00 +03:00
result = "dev";
2018-09-17 10:07:32 +03:00
break;
case EXPERIMENTAL:
2018-09-22 17:33:00 +03:00
result = "experimental";
2018-09-17 10:07:32 +03:00
break;
case UNKNOWN:
2018-09-22 17:33:00 +03:00
result = "";
2018-09-17 10:07:32 +03:00
break;
default:
2018-09-22 17:33:00 +03:00
result = "";
2018-09-17 10:07:32 +03:00
break;
}
return result;
}
2018-09-22 17:33:00 +03:00
2018-09-17 10:07:32 +03:00
@Override
@LauncherAPI
2018-09-17 10:07:32 +03:00
public String toString() {
2018-09-22 17:33:00 +03:00
return String.format("%d.%d.%d-%d %s", major, minor, patch, build, getReleaseStatus());
2018-09-17 10:07:32 +03:00
}
2018-09-22 17:33:00 +03:00
@LauncherAPI
2018-09-22 17:33:00 +03:00
public enum Type {
2018-09-17 10:07:32 +03:00
LTS,
STABLE,
BETA,
ALPHA,
DEV,
EXPERIMENTAL,
UNKNOWN
}
}