Package de.Keyle.MyPet.api.skill
Class UpgradeParsers
java.lang.Object
de.Keyle.MyPet.api.skill.UpgradeParsers
Helpers for
UpgradeParser implementations. Each parseXxx
method takes a JsonElement from an upgrade JSON node and returns the
corresponding modifier, or null if the element is absent or has the
wrong shape.-
Method Summary
Modifier and TypeMethodDescriptionstatic JsonElementget(JsonObject o, String key) Looks up a key in a JSON object, ignoring case.static UpgradeBooleanModifierparseBoolean(JsonElement modifier) Parses a JSON boolean primitive into a boolean upgrade modifier.static <T extends Enum<T>>
UpgradeEnumModifier<T> parseEnum(JsonElement modifier, Class<T> enumClass) Parses a JSON string into an enum upgrade modifier by matching the string (case-insensitive) against the constants of the given enum class.static UpgradeIntegerModifierparseInteger(JsonElement modifier) Parses a JSON string element into an integer upgrade modifier.static UpgradeNumberModifierparseNumber(JsonElement modifier) Parses a JSON string element into a numeric upgrade modifier.
-
Method Details
-
get
Looks up a key in a JSON object, ignoring case. Returnsnullif the object isnullor no key matches.- Parameters:
o- the JSON object to readkey- the key to look for- Returns:
- the value, or
nullwhen the key is absent
-
parseNumber
Parses a JSON string element into a numeric upgrade modifier. Expects a string prefixed with"+"(add) or"-"(subtract) followed by a decimal number (e.g."+5","-2.5").- Parameters:
modifier- the JSON element to parse- Returns:
- the modifier, or
nullif the element is not a prefixed numeric string
-
parseInteger
Parses a JSON string element into an integer upgrade modifier. Same format asparseNumber(JsonElement)but truncates the parsed value to anint.- Parameters:
modifier- the JSON element to parse- Returns:
- the modifier, or
nullif the element is not a prefixed numeric string
-
parseBoolean
Parses a JSON boolean primitive into a boolean upgrade modifier.- Parameters:
modifier- the JSON element to parse- Returns:
UpgradeBooleanModifier.TrueorUpgradeBooleanModifier.False, ornullif the element is not a boolean primitive
-
parseEnum
public static <T extends Enum<T>> UpgradeEnumModifier<T> parseEnum(JsonElement modifier, Class<T> enumClass) Parses a JSON string into an enum upgrade modifier by matching the string (case-insensitive) against the constants of the given enum class.- Type Parameters:
T- the enum type- Parameters:
modifier- the JSON element to parseenumClass- the enum type to match against- Returns:
- the matching modifier, or
nullif no constant matches or the element is not a string
-