Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1474,8 +1474,8 @@ public Optional<Section> getParent(@NotNull String route) {
* @param route the route to get the value at
* @return the value, or section at the given route
*/
public Optional<Object> getOptional(@NotNull Route route) {
return getOptionalBlock(route).map(block -> block instanceof Section ? block : block.getStoredValue());
public Optional<Object> getOptional(@NotNull String route) {
return getOptional(Route.fromString(route));
}

/**
Expand All @@ -1487,7 +1487,7 @@ public Optional<Object> getOptional(@NotNull Route route) {
* @param route the route to get the value at
* @return the value, or section at the given route
*/
public Optional<Object> getOptional(@NotNull String route) {
public Optional<Object> getOptional(@NotNull Route route) {
return getOptionalBlock(route).map(block -> block instanceof Section ? block : block.getStoredValue());
}

Expand Down Expand Up @@ -1582,13 +1582,10 @@ public Object get(@NotNull String route, @Nullable Object def) {
* @return the value cast to the given type
*/
@SuppressWarnings("unchecked")
public <T> Optional<T> getAsOptional(@NotNull Route route, @NotNull Class<T> 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 <T> Optional<T> getAsOptional(@NotNull String route, @NotNull Class<T> 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
Expand All @@ -1607,7 +1604,7 @@ public <T> Optional<T> getAsOptional(@NotNull Route route, @NotNull Class<T> cla
* @return the value cast to the given type
*/
@SuppressWarnings("unchecked")
public <T> Optional<T> getAsOptional(@NotNull String route, @NotNull Class<T> clazz) {
public <T> Optional<T> getAsOptional(@NotNull Route route, @NotNull Class<T> 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);
Expand All @@ -1630,8 +1627,8 @@ public <T> Optional<T> getAsOptional(@NotNull String route, @NotNull Class<T> cl
* @param <T> the target type
* @return the value cast to the given type, or default according to the documentation above
*/
public <T> T getAs(@NotNull Route route, @NotNull Class<T> clazz) {
return getAsOptional(route, clazz).orElseGet(() -> canUseDefaults() ? defaults.getAs(route, clazz) : null);
public <T> T getAs(@NotNull String route, @NotNull Class<T> clazz) {
return getAs(Route.fromString(route), clazz);
}

/**
Expand All @@ -1651,7 +1648,7 @@ public <T> T getAs(@NotNull Route route, @NotNull Class<T> clazz) {
* @param <T> the target type
* @return the value cast to the given type, or default according to the documentation above
*/
public <T> T getAs(@NotNull String route, @NotNull Class<T> clazz) {
public <T> T getAs(@NotNull Route route, @NotNull Class<T> clazz) {
return getAsOptional(route, clazz).orElseGet(() -> canUseDefaults() ? defaults.getAs(route, clazz) : null);
}

Expand Down Expand Up @@ -4726,4 +4723,4 @@ public List<Short> getShortList(@NotNull String route) {
return getOptionalMapList(route).orElseGet(() -> canUseDefaults() ? defaults.getMapList(route) : root.getGeneralSettings().getDefaultList());
}

}
}