mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Fix 2 minor smells
This commit is contained in:
parent
f85a2b1017
commit
c55f44a3e5
@ -46,7 +46,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
private final Path jsonDirectory;
|
||||
|
||||
private final Pattern timestampRegex = Pattern.compile(".*-([0-9]*).json");
|
||||
private final String jsonFileExtension = ".json";
|
||||
private static final String JSON_FILE_EXTENSION = ".json";
|
||||
|
||||
@Inject
|
||||
public JSONFileStorage(PlanFiles files, PluginLogger logger) {
|
||||
@ -57,7 +57,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
|
||||
@Override
|
||||
public StoredJSON storeJson(String identifier, String json, long timestamp) {
|
||||
Path writingTo = jsonDirectory.resolve(identifier + '-' + timestamp + jsonFileExtension);
|
||||
Path writingTo = jsonDirectory.resolve(identifier + '-' + timestamp + JSON_FILE_EXTENSION);
|
||||
try {
|
||||
Files.createDirectories(jsonDirectory);
|
||||
Files.write(writingTo, json.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
|
||||
@ -73,7 +73,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
if (stored == null) return Optional.empty();
|
||||
for (File file : stored) {
|
||||
String fileName = file.getName();
|
||||
if (fileName.endsWith(jsonFileExtension) && fileName.startsWith(identifier)) {
|
||||
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier)) {
|
||||
return Optional.ofNullable(readStoredJSON(file));
|
||||
}
|
||||
}
|
||||
@ -101,7 +101,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
|
||||
@Override
|
||||
public Optional<StoredJSON> fetchExactJson(String identifier, long timestamp) {
|
||||
File found = jsonDirectory.resolve(identifier + "-" + timestamp + jsonFileExtension).toFile();
|
||||
File found = jsonDirectory.resolve(identifier + "-" + timestamp + JSON_FILE_EXTENSION).toFile();
|
||||
if (!found.exists()) return Optional.empty();
|
||||
return Optional.ofNullable(readStoredJSON(found));
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
for (File file : stored) {
|
||||
try {
|
||||
String fileName = file.getName();
|
||||
if (fileName.endsWith(jsonFileExtension) && fileName.startsWith(identifier)) {
|
||||
if (fileName.endsWith(JSON_FILE_EXTENSION) && fileName.startsWith(identifier)) {
|
||||
Matcher timestampMatch = timestampRegex.matcher(fileName);
|
||||
if (timestampMatch.find() && timestampComparator.test(timestampMatch, timestamp)) {
|
||||
return Optional.ofNullable(readStoredJSON(file));
|
||||
|
@ -51,7 +51,8 @@ public class VersionChecker implements SubSystem {
|
||||
private final PluginLogger logger;
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final ErrorLogger errorLogger;
|
||||
private final String downloadIconHtml = "<i class=\"fa fa-fw fa-download\"></i> ";
|
||||
|
||||
private static final String DOWNLOAD_ICON_HTML = "<i class=\"fa fa-fw fa-download\"></i> ";
|
||||
|
||||
private VersionInfo newVersionAvailable;
|
||||
|
||||
@ -132,7 +133,7 @@ public class VersionChecker implements SubSystem {
|
||||
"font-size: 0.95rem;" : "";
|
||||
return "<button class=\"btn bg-white col-plan\" style=\"" + reduceFontSize +
|
||||
"\" data-target=\"#updateModal\" data-toggle=\"modal\" type=\"button\">" +
|
||||
downloadIconHtml + locale.getString(PluginLang.VERSION_UPDATE) + ": " + v.getVersion().getVersionString() +
|
||||
DOWNLOAD_ICON_HTML + locale.getString(PluginLang.VERSION_UPDATE) + ": " + v.getVersion().getVersionString() +
|
||||
"</button>";
|
||||
}
|
||||
);
|
||||
@ -148,7 +149,7 @@ public class VersionChecker implements SubSystem {
|
||||
return getNewVersionAvailable()
|
||||
.map(v -> "<div class=\"modal-header\">" +
|
||||
"<h5 class=\"modal-title\" id=\"updateModalLabel\">" +
|
||||
downloadIconHtml + locale.getString(PluginLang.VERSION_UPDATE_AVAILABLE, v.getVersion().getVersionString()) +
|
||||
DOWNLOAD_ICON_HTML + locale.getString(PluginLang.VERSION_UPDATE_AVAILABLE, v.getVersion().getVersionString()) +
|
||||
"</h5><button aria-label=\"Close\" class=\"close\" data-dismiss=\"modal\" type=\"button\"><span aria-hidden=\"true\">×</span></button>" +
|
||||
"</div>" + // Close modal-header
|
||||
"<div class=\"modal-body\">" +
|
||||
@ -157,7 +158,7 @@ public class VersionChecker implements SubSystem {
|
||||
"<a class=\"btn col-plan\" href=\"" + v.getChangeLogUrl() + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
|
||||
"<i class=\"fa fa-fw fa-list\"></i> " + locale.getString(PluginLang.VERSION_CHANGE_LOG) + "</a>" +
|
||||
"<a class=\"btn col-plan\" href=\"" + v.getDownloadUrl() + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
|
||||
downloadIconHtml + locale.getString(PluginLang.VERSION_DOWNLOAD, v.getVersion().getVersionString()) + "</a>" +
|
||||
DOWNLOAD_ICON_HTML + locale.getString(PluginLang.VERSION_DOWNLOAD, v.getVersion().getVersionString()) + "</a>" +
|
||||
"</div>") // Close modal-body
|
||||
.orElse("<div class=\"modal-header\">" +
|
||||
"<h5 class=\"modal-title\" id=\"updateModalLabel\">" +
|
||||
|
Loading…
Reference in New Issue
Block a user