Removes dead code and cleans up annotations Nullable/NonNull annotations.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.majinnaibu.monstercards.helpers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ArrayHelper {
|
||||
public static int indexOf(Object[] array, Object target) {
|
||||
public static int indexOf(@NonNull Object[] array, Object target) {
|
||||
for (int index = 0; index < array.length; index++) {
|
||||
if (Objects.equals(array[index], target)) {
|
||||
return index;
|
||||
|
||||
@@ -4,9 +4,6 @@ import org.commonmark.node.Document;
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.node.Paragraph;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.NodeRenderer;
|
||||
import org.commonmark.renderer.html.HtmlNodeRendererContext;
|
||||
import org.commonmark.renderer.html.HtmlNodeRendererFactory;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
|
||||
public final class CommonMarkHelper {
|
||||
@@ -27,12 +24,4 @@ public final class CommonMarkHelper {
|
||||
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
||||
return renderer.render(document);
|
||||
}
|
||||
|
||||
private static final class MyNodeRendererFactory implements HtmlNodeRendererFactory {
|
||||
|
||||
@Override
|
||||
public NodeRenderer create(HtmlNodeRendererContext context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.majinnaibu.monstercards.helpers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -15,17 +17,16 @@ import com.majinnaibu.monstercards.models.Monster;
|
||||
import com.majinnaibu.monstercards.models.Skill;
|
||||
import com.majinnaibu.monstercards.models.Trait;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class MonsterImportHelper {
|
||||
@NonNull
|
||||
public static Monster fromJSON(String json) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject rootDict = parser.parse(json).getAsJsonObject();
|
||||
JsonObject rootDict = JsonParser.parseString(json).getAsJsonObject();
|
||||
|
||||
Monster monster = new Monster();
|
||||
monster.name = Helpers.getString(rootDict, "name");
|
||||
@@ -110,7 +111,7 @@ public class MonsterImportHelper {
|
||||
return getString(dict, name, "");
|
||||
}
|
||||
|
||||
public static String getString(@NotNull JsonObject dict, String name, String defaultValue) {
|
||||
public static String getString(@NonNull JsonObject dict, String name, String defaultValue) {
|
||||
if (dict.has(name)) {
|
||||
return dict.get(name).getAsString();
|
||||
}
|
||||
@@ -122,13 +123,19 @@ public class MonsterImportHelper {
|
||||
return getInt(dict, name, 0);
|
||||
}
|
||||
|
||||
public static int getInt(@NotNull JsonObject dict, String name, int defaultValue) {
|
||||
public static int getInt(@NonNull JsonObject dict, String name, int defaultValue) {
|
||||
if (dict.has(name)) {
|
||||
JsonElement element = dict.get(name);
|
||||
if (element.isJsonPrimitive()) {
|
||||
JsonPrimitive rawValue = element.getAsJsonPrimitive();//dict.getAsJsonPrimitive(name);
|
||||
JsonPrimitive rawValue = element.getAsJsonPrimitive();
|
||||
if (rawValue.isNumber()) {
|
||||
return rawValue.getAsInt();
|
||||
} else {
|
||||
try {
|
||||
return rawValue.getAsInt();
|
||||
} catch (Exception ex) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,22 +146,29 @@ public class MonsterImportHelper {
|
||||
return getBool(dict, name, false);
|
||||
}
|
||||
|
||||
public static boolean getBool(@NotNull JsonObject dict, String name, boolean defaultValue) {
|
||||
public static boolean getBool(@NonNull JsonObject dict, String name, boolean defaultValue) {
|
||||
if (dict.has(name)) {
|
||||
JsonElement element = dict.get(name);
|
||||
if (element.isJsonPrimitive()) {
|
||||
JsonPrimitive rawValue = element.getAsJsonPrimitive();
|
||||
if (rawValue.isBoolean()) {
|
||||
return rawValue.getAsBoolean();
|
||||
} else {
|
||||
try {
|
||||
return rawValue.getAsBoolean();
|
||||
} catch (Exception ex) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
public static String formatDistance(String name, int distance) {
|
||||
return String.format("%s %d ft.", name, distance);
|
||||
// TODO: consider moving this to a string resource so it can be localized
|
||||
return String.format(Locale.getDefault(), "%s %d ft.", name, distance);
|
||||
}
|
||||
|
||||
public static void addSense(Monster monster, JsonObject root, String name) {
|
||||
@@ -164,8 +178,8 @@ public class MonsterImportHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Trait> getListOfTraits(@NotNull JsonObject dict, String name) {
|
||||
@NonNull
|
||||
public static List<Trait> getListOfTraits(@NonNull JsonObject dict, String name) {
|
||||
ArrayList<Trait> traits = new ArrayList<>();
|
||||
if (dict.has(name)) {
|
||||
JsonElement arrayElement = dict.get(name);
|
||||
@@ -187,7 +201,7 @@ public class MonsterImportHelper {
|
||||
return traits;
|
||||
}
|
||||
|
||||
public static void addSavingThrows(Monster monster, JsonObject root) {
|
||||
public static void addSavingThrows(Monster monster, @NonNull JsonObject root) {
|
||||
if (root.has("sthrows")) {
|
||||
JsonElement arrayElement = root.get("sthrows");
|
||||
if (arrayElement.isJsonArray()) {
|
||||
@@ -217,7 +231,8 @@ public class MonsterImportHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<Skill> getSetOfSkills(JsonObject root) {
|
||||
@NonNull
|
||||
public static Set<Skill> getSetOfSkills(@NonNull JsonObject root) {
|
||||
HashSet<Skill> skills = new HashSet<>();
|
||||
if (root.has("skills")) {
|
||||
JsonElement arrayElement = root.get("skills");
|
||||
@@ -241,11 +256,13 @@ public class MonsterImportHelper {
|
||||
return skills;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Set<String> getSetOfDamageTypes(JsonObject rootDict, String name) {
|
||||
return getSetOfDamageTypes(rootDict, name, null);
|
||||
}
|
||||
|
||||
public static Set<String> getSetOfDamageTypes(JsonObject root, String name, String type) {
|
||||
@NonNull
|
||||
public static Set<String> getSetOfDamageTypes(@NonNull JsonObject root, String name, String type) {
|
||||
HashSet<String> damageTypes = new HashSet<>();
|
||||
if (root.has(name)) {
|
||||
JsonElement arrayElement = root.get(name);
|
||||
@@ -268,7 +285,8 @@ public class MonsterImportHelper {
|
||||
return damageTypes;
|
||||
}
|
||||
|
||||
public static Set<Language> getSetOfLanguages(JsonObject root, String name) {
|
||||
@NonNull
|
||||
public static Set<Language> getSetOfLanguages(@NonNull JsonObject root, String name) {
|
||||
HashSet<Language> languages = new HashSet<>();
|
||||
if (root.has(name)) {
|
||||
JsonElement arrayElement = root.get(name);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.majinnaibu.monstercards.helpers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@SuppressWarnings({"RedundantIfStatement"})
|
||||
@@ -16,7 +19,8 @@ public final class StringHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String join(String delimiter, Collection<String> strings) {
|
||||
@NonNull
|
||||
public static String join(String delimiter, @NonNull Collection<String> strings) {
|
||||
int length = strings.size();
|
||||
if (length < 1) {
|
||||
return "";
|
||||
@@ -36,7 +40,7 @@ public final class StringHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static String oxfordJoin(String delimiter, String lastDelimiter, String onlyDelimiter, Collection<String> strings) {
|
||||
public static String oxfordJoin(String delimiter, String lastDelimiter, String onlyDelimiter, @NonNull Collection<String> strings) {
|
||||
int length = strings.size();
|
||||
if (length < 1) {
|
||||
return "";
|
||||
@@ -59,6 +63,7 @@ public final class StringHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer parseInt(String s) {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
@@ -67,7 +72,7 @@ public final class StringHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean containsCaseInsensitive(String text, String search) {
|
||||
public static boolean containsCaseInsensitive(@NonNull String text, @NonNull String search) {
|
||||
// TODO: find a locale independent way to do this
|
||||
return text.toLowerCase().contains(search.toLowerCase());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user