diff --git a/src/main/java/dev/dejvokep/boostedyaml/block/implementation/Section.java b/src/main/java/dev/dejvokep/boostedyaml/block/implementation/Section.java index ed374e6..4c52e30 100644 --- a/src/main/java/dev/dejvokep/boostedyaml/block/implementation/Section.java +++ b/src/main/java/dev/dejvokep/boostedyaml/block/implementation/Section.java @@ -1474,8 +1474,8 @@ public Optional
getParent(@NotNull String route) { * @param route the route to get the value at * @return the value, or section at the given route */ - public Optional getOptional(@NotNull Route route) { - return getOptionalBlock(route).map(block -> block instanceof Section ? block : block.getStoredValue()); + public Optional getOptional(@NotNull String route) { + return getOptional(Route.fromString(route)); } /** @@ -1487,7 +1487,7 @@ public Optional getOptional(@NotNull Route route) { * @param route the route to get the value at * @return the value, or section at the given route */ - public Optional getOptional(@NotNull String route) { + public Optional getOptional(@NotNull Route route) { return getOptionalBlock(route).map(block -> block instanceof Section ? block : block.getStoredValue()); } @@ -1582,13 +1582,10 @@ public Object get(@NotNull String route, @Nullable Object def) { * @return the value cast to the given type */ @SuppressWarnings("unchecked") - public Optional getAsOptional(@NotNull Route route, @NotNull Class clazz) { - return getOptional(route).map((object) -> clazz.isInstance(object) ? (T) object : - PrimitiveConversions.isNumber(object.getClass()) && PrimitiveConversions.isNumber(clazz) ? (T) convertNumber(object, clazz) : - NON_NUMERIC_CONVERSIONS.containsKey(object.getClass()) && NON_NUMERIC_CONVERSIONS.containsKey(clazz) ? (T) object : null); + public Optional getAsOptional(@NotNull String route, @NotNull Class clazz) { + return getAsOptional(Route.fromString(route), clazz); } - /** * Returns the value of the block (the actual value) at the given route, or if it is a section, the corresponding * {@link Section} instance, in both cases cast to instance of the given class; encapsulated in an instance of @@ -1607,7 +1604,7 @@ public Optional getAsOptional(@NotNull Route route, @NotNull Class cla * @return the value cast to the given type */ @SuppressWarnings("unchecked") - public Optional getAsOptional(@NotNull String route, @NotNull Class clazz) { + public Optional getAsOptional(@NotNull Route route, @NotNull Class clazz) { return getOptional(route).map((object) -> clazz.isInstance(object) ? (T) object : PrimitiveConversions.isNumber(object.getClass()) && PrimitiveConversions.isNumber(clazz) ? (T) convertNumber(object, clazz) : NON_NUMERIC_CONVERSIONS.containsKey(object.getClass()) && NON_NUMERIC_CONVERSIONS.containsKey(clazz) ? (T) object : null); @@ -1630,8 +1627,8 @@ public Optional getAsOptional(@NotNull String route, @NotNull Class cl * @param the target type * @return the value cast to the given type, or default according to the documentation above */ - public T getAs(@NotNull Route route, @NotNull Class clazz) { - return getAsOptional(route, clazz).orElseGet(() -> canUseDefaults() ? defaults.getAs(route, clazz) : null); + public T getAs(@NotNull String route, @NotNull Class clazz) { + return getAs(Route.fromString(route), clazz); } /** @@ -1651,7 +1648,7 @@ public T getAs(@NotNull Route route, @NotNull Class clazz) { * @param the target type * @return the value cast to the given type, or default according to the documentation above */ - public T getAs(@NotNull String route, @NotNull Class clazz) { + public T getAs(@NotNull Route route, @NotNull Class clazz) { return getAsOptional(route, clazz).orElseGet(() -> canUseDefaults() ? defaults.getAs(route, clazz) : null); } @@ -4726,4 +4723,4 @@ public List getShortList(@NotNull String route) { return getOptionalMapList(route).orElseGet(() -> canUseDefaults() ? defaults.getMapList(route) : root.getGeneralSettings().getDefaultList()); } -} \ No newline at end of file +}