Skip to content

Commit

Permalink
Replace getSectionOrCreate(...) with `getConfigurationSectionOption…
Browse files Browse the repository at this point in the history
…al(...)` in `AnnoyingFile`
  • Loading branch information
srnyx committed Nov 17, 2024
1 parent 631002d commit 235db9a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,30 @@ public void log(@NotNull Level level, @Nullable String key, @NotNull String mess
}

/**
* Gets the {@link ConfigurationSection} at the path or creates an empty one it if it doesn't exist
* Gets the default value from the path
*
* @param path the path to the node
*
* @return the {@link ConfigurationSection} at the path or a new one if it doesn't exist
* @return the default value or empty if it doesn't exist
*
* @param <G> the type of the default value
*/
@NotNull
public ConfigurationSection getSectionOrCreate(@NotNull String path) {
final ConfigurationSection section = getConfigurationSection(path);
return section == null ? createSection(path) : section;
public <G> Optional<G> getDef(@NotNull String path) {
final Object value = getDefault(path);
return value != null ? Optional.of((G) value) : Optional.empty();
}

/**
* Gets the default value from the path
* Get a {@link ConfigurationSection} from the path in an {@link Optional}
*
* @param path the path to the node
*
* @return the default value or empty if it doesn't exist
*
* @param <G> the type of the default value
* @return the {@link ConfigurationSection} or empty if it doesn't exist
*/
@NotNull
public <G> Optional<G> getDef(@NotNull String path) {
final Object value = getDefault(path);
return value != null ? Optional.of((G) value) : Optional.empty();
public Optional<ConfigurationSection> getConfigurationSectionOptional(@NotNull String path) {
return Optional.ofNullable(getConfigurationSection(path));
}

/**
Expand Down

0 comments on commit 235db9a

Please sign in to comment.