Skip to content

Commit

Permalink
fix: versionInfo to BundleInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Jun 29, 2022
1 parent 7df3471 commit d5c300e
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Objects;
import java.util.TimeZone;

public class VersionInfo {
public class BundleInfo {
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

public static final String VERSION_BUILTIN = "builtin";
Expand All @@ -20,25 +20,25 @@ public class VersionInfo {

private final String downloaded;
private final String folder;
private final String versionName;
private final VersionStatus status;
private final String version;
private final BundleStatus status;

static {
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
}

public VersionInfo(final VersionInfo source) {
this(source.folder, source.versionName, source.status, source.downloaded);
public BundleInfo(final BundleInfo source) {
this(source.folder, source.version, source.status, source.downloaded);
}

public VersionInfo(final String folder, final String version, final VersionStatus status, final Date downloaded) {
public BundleInfo(final String folder, final String version, final BundleStatus status, final Date downloaded) {
this(folder, version, status, sdf.format(downloaded));
}

public VersionInfo(final String folder, final String version, final VersionStatus status, final String downloaded) {
public BundleInfo(final String folder, final String version, final BundleStatus status, final String downloaded) {
this.downloaded = downloaded.trim();
this.folder = folder;
this.versionName = version;
this.version = version;
this.status = status;
}

Expand All @@ -49,7 +49,7 @@ public Boolean isUnknown() {
return VERSION_UNKNOWN.equals(this.folder);
}
public Boolean isErrorStatus() {
return VersionStatus.ERROR == this.status;
return BundleStatus.ERROR == this.status;
}
public boolean isDownloaded() {
return !this.isBuiltin() && this.downloaded != null && !this.downloaded.equals("");
Expand All @@ -59,52 +59,52 @@ public String getDownloaded() {
return this.isBuiltin() ? DOWNLOADED_BUILTIN : this.downloaded;
}

public VersionInfo setDownloaded(Date downloaded) {
return new VersionInfo(this.folder, this.versionName, this.status, downloaded);
public BundleInfo setDownloaded(Date downloaded) {
return new BundleInfo(this.folder, this.version, this.status, downloaded);
}

public String getFolder() {
return this.isBuiltin() ? VERSION_BUILTIN : this.folder;
}

public VersionInfo setFolder(String folder) {
return new VersionInfo(folder, this.versionName, this.status, this.downloaded);
public BundleInfo setFolder(String folder) {
return new BundleInfo(folder, this.version, this.status, this.downloaded);
}

public String getVersionName() {
return this.versionName == null ? VERSION_BUILTIN : this.versionName;
return this.version == null ? VERSION_BUILTIN : this.version;
}

public VersionInfo setVersionName(String version) {
return new VersionInfo(this.folder, version, this.status, this.downloaded);
public BundleInfo setVersionName(String version) {
return new BundleInfo(this.folder, version, this.status, this.downloaded);
}

public VersionStatus getStatus() {
return this.isBuiltin() ? VersionStatus.SUCCESS : this.status;
public BundleStatus getStatus() {
return this.isBuiltin() ? BundleStatus.SUCCESS : this.status;
}

public VersionInfo setStatus(VersionStatus status) {
return new VersionInfo(this.folder, this.versionName, status, this.downloaded);
public BundleInfo setStatus(BundleStatus status) {
return new BundleInfo(this.folder, this.version, status, this.downloaded);
}

public static VersionInfo fromJSON(final JSObject json) throws JSONException {
return VersionInfo.fromJSON(json.toString());
public static BundleInfo fromJSON(final JSObject json) throws JSONException {
return BundleInfo.fromJSON(json.toString());
}

public static VersionInfo fromJSON(final String jsonString) throws JSONException {
public static BundleInfo fromJSON(final String jsonString) throws JSONException {
JSONObject json = new JSONObject(new JSONTokener(jsonString));
return new VersionInfo(
return new BundleInfo(
json.has("folder") ? json.getString("folder") : "",
json.has("versionName") ? json.getString("versionName") : VersionInfo.VERSION_UNKNOWN,
json.has("status") ? VersionStatus.fromString(json.getString("status")) : VersionStatus.PENDING,
json.has("version") ? json.getString("version") : BundleInfo.VERSION_UNKNOWN,
json.has("status") ? BundleStatus.fromString(json.getString("status")) : BundleStatus.PENDING,
json.has("downloaded") ? json.getString("downloaded") : ""
);
}

public JSObject toJSON() {
final JSObject result = new JSObject();
result.put("folder", this.getFolder());
result.put("versionName", this.getVersionName());
result.put("version", this.getVersionName());
result.put("downloaded", this.getDownloaded());
result.put("status", this.getStatus());
return result;
Expand All @@ -113,14 +113,14 @@ public JSObject toJSON() {
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof VersionInfo)) return false;
final VersionInfo that = (VersionInfo) o;
if (!(o instanceof BundleInfo)) return false;
final BundleInfo that = (BundleInfo) o;
return this.getFolder().equals(that.getFolder());
}

@Override
public int hashCode() {
return Objects.hash(this.versionName);
return Objects.hash(this.version);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import java.util.HashMap;
import java.util.Map;

public enum VersionStatus {
public enum BundleStatus {
SUCCESS("success"),
ERROR("error"),
PENDING("pending"),
DOWNLOADING("donwloading");

public final String label;

private static final Map<String, VersionStatus> BY_LABEL = new HashMap<>();
private static final Map<String, BundleStatus> BY_LABEL = new HashMap<>();
static {
for (final VersionStatus e: values()) {
for (final BundleStatus e: values()) {
BY_LABEL.put(e.label, e);
}
}

VersionStatus(final String label) {
BundleStatus(final String label) {
this.label = label;
}

Expand All @@ -27,10 +27,10 @@ public String toString() {
return this.label;
}

public static VersionStatus fromString(final String status) {
public static BundleStatus fromString(final String status) {
if(status == null || status.isEmpty()) {
return VersionStatus.PENDING;
return BundleStatus.PENDING;
}
return VersionStatus.BY_LABEL.get(status);
return BundleStatus.BY_LABEL.get(status);
}
}

0 comments on commit d5c300e

Please sign in to comment.