Replace doubled map lookups

This commit is contained in:
KennyTV 2020-07-11 10:27:30 +02:00 committed by MiniDigger
parent 119c7fbf9e
commit b84c97c939
3 changed files with 80 additions and 58 deletions

View File

@ -28,41 +28,49 @@ public class PaperPluginFileHandler extends FileTypeHandler {
Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(reader);
if (data == null || data.size() == 0) {
if (data == null || data.isEmpty()) {
return result;
}
if (data.containsKey("version")) {
result.add(new StringDataValue("version", (String) data.get("version")));
String version = (String) data.get("version");
if (version != null) {
result.add(new StringDataValue("version", version));
}
if (data.containsKey("name")) {
result.add(new StringDataValue("name", (String) data.get("name")));
String name = (String) data.get("name");
if (name != null) {
result.add(new StringDataValue("name", name));
}
if (data.containsKey("description")) {
result.add(new StringDataValue("description", (String) data.get("description")));
String description = (String) data.get("description");
if (description != null) {
result.add(new StringDataValue("description", description));
}
if (data.containsKey("website")) {
result.add(new StringDataValue("url", (String) data.get("website")));
String website = (String) data.get("website");
if (website != null) {
result.add(new StringDataValue("url", website));
}
if (data.containsKey("author")) {
result.add(new DataValue.StringListDataValue("authors", List.of((String) data.get("author"))));
String author = (String) data.get("author");
if (author != null) {
result.add(new DataValue.StringListDataValue("authors", List.of(author)));
}
if (data.containsKey("authors")) {
//noinspection unchecked
result.add(new StringListDataValue("authors", (List<String>) data.get("authors")));
List<String> authors = (List<String>) data.get("authors");
if (authors != null) {
result.add(new StringListDataValue("authors", authors));
}
List<Dependency> dependencies = new ArrayList<>();
if (data.containsKey("softdepend")) {
//noinspection unchecked
dependencies.addAll(((List<String>) data.get("softdepend")).stream().map(p -> new Dependency(p, null, false)).collect(Collectors.toList()));
//noinspection unchecked
List<String> softdepend = (List<String>) data.get("softdepend");
if (softdepend != null) {
dependencies.addAll(softdepend.stream().map(p -> new Dependency(p, null, false)).collect(Collectors.toList()));
}
if (data.containsKey("depend")) {
//noinspection unchecked
dependencies.addAll(((List<String>) data.get("depend")).stream().map(p -> new Dependency(p, null)).collect(Collectors.toList()));
//noinspection unchecked
List<String> depend = (List<String>) data.get("depend");
if (depend != null) {
dependencies.addAll(depend.stream().map(p -> new Dependency(p, null)).collect(Collectors.toList()));
}
String paperVersion = data.getOrDefault("api-version", "").toString();
Dependency paperDependency = new Dependency("paperapi", paperVersion.length() > 0 ? paperVersion : null);
Dependency paperDependency = new Dependency("paperapi", !paperVersion.isEmpty() ? paperVersion : null);
dependencies.add(paperDependency);
result.add(new DependencyDataValue("dependencies", dependencies));

View File

@ -25,33 +25,39 @@ public class VelocityFileHandler extends FileTypeHandler {
Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(reader);
if (data == null || data.size() == 0) {
if (data == null || data.isEmpty()) {
return result;
}
if (data.containsKey("version")) {
result.add(new DataValue.StringDataValue("version", (String) data.get("version")));
String version = (String) data.get("version");
if (version != null) {
result.add(new DataValue.StringDataValue("version", version));
}
if (data.containsKey("name")) {
result.add(new DataValue.StringDataValue("name", (String) data.get("name")));
String name = (String) data.get("name");
if (name != null) {
result.add(new DataValue.StringDataValue("name", name));
}
if (data.containsKey("description")) {
result.add(new DataValue.StringDataValue("description", (String) data.get("description")));
String description = (String) data.get("description");
if (description != null) {
result.add(new DataValue.StringDataValue("description", description));
}
if (data.containsKey("url")) {
result.add(new DataValue.StringDataValue("url", (String) data.get("url")));
String url = (String) data.get("url");
if (url != null) {
result.add(new DataValue.StringDataValue("url", url));
}
if (data.containsKey("author")) {
result.add(new DataValue.StringListDataValue("authors", List.of((String) data.get("author"))));
String author = (String) data.get("author");
if (author != null) {
result.add(new DataValue.StringListDataValue("authors", List.of(author)));
}
if (data.containsKey("authors")) {
//noinspection unchecked
result.add(new DataValue.StringListDataValue("authors", (List<String>) data.get("authors")));
//noinspection unchecked
List<String> authors = (List<String>) data.get("authors");
if (authors != null) {
result.add(new DataValue.StringListDataValue("authors", authors));
}
List<Dependency> dependencies;
if (data.containsKey("dependencies")) {
//noinspection unchecked
List<Map<String, Object>> deps = (List<Map<String, Object>>) data.get("dependencies");
//noinspection unchecked
List<Map<String, Object>> deps = (List<Map<String, Object>>) data.get("dependencies");
if (deps != null) {
dependencies = deps.stream().map(p -> new Dependency((String) p.get("id"), null, !(boolean) p.getOrDefault("optional", false))).collect(Collectors.toList());
} else {
dependencies = new ArrayList<>();

View File

@ -25,38 +25,46 @@ public class WaterfallPluginFileHandler extends FileTypeHandler {
Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(reader);
if (data == null || data.size() == 0) {
if (data == null || data.isEmpty()) {
return result;
}
if (data.containsKey("version")) {
result.add(new DataValue.StringDataValue("version", (String) data.get("version")));
String version = (String) data.get("version");
if (version != null) {
result.add(new DataValue.StringDataValue("version", version));
}
if (data.containsKey("name")) {
result.add(new DataValue.StringDataValue("name", (String) data.get("name")));
String name = (String) data.get("name");
if (name != null) {
result.add(new DataValue.StringDataValue("name", name));
}
if (data.containsKey("description")) {
result.add(new DataValue.StringDataValue("description", (String) data.get("description")));
String description = (String) data.get("description");
if (description != null) {
result.add(new DataValue.StringDataValue("description", description));
}
if (data.containsKey("website")) {
result.add(new DataValue.StringDataValue("url", (String) data.get("website")));
String website = (String) data.get("website");
if (website != null) {
result.add(new DataValue.StringDataValue("url", website));
}
if (data.containsKey("author")) {
result.add(new DataValue.StringListDataValue("authors", List.of((String) data.get("author"))));
String author = (String) data.get("author");
if (author != null) {
result.add(new DataValue.StringListDataValue("authors", List.of(author)));
}
if (data.containsKey("authors")) {
//noinspection unchecked
result.add(new DataValue.StringListDataValue("authors", (List<String>) data.get("authors")));
//noinspection unchecked
List<String> authors = (List<String>) data.get("authors");
if (authors != null) {
result.add(new DataValue.StringListDataValue("authors", authors));
}
List<Dependency> dependencies = new ArrayList<>();
if (data.containsKey("softdepend")) {
//noinspection unchecked
dependencies.addAll(((List<String>) data.get("softdepend")).stream().map(p -> new Dependency(p, null, false)).collect(Collectors.toList()));
//noinspection unchecked
List<String> softdepend = (List<String>) data.get("softdepend");
if (softdepend != null) {
dependencies.addAll(softdepend.stream().map(p -> new Dependency(p, null, false)).collect(Collectors.toList()));
}
if (data.containsKey("depend")) {
//noinspection unchecked
dependencies.addAll(((List<String>) data.get("depend")).stream().map(p -> new Dependency(p, null)).collect(Collectors.toList()));
//noinspection unchecked
List<String> depend = (List<String>) data.get("depend");
if (depend != null) {
dependencies.addAll(depend.stream().map(p -> new Dependency(p, null)).collect(Collectors.toList()));
}
dependencies.add(new Dependency("waterfall", null));