Skip to content

Commit

Permalink
1.6.18
Browse files Browse the repository at this point in the history
  • Loading branch information
ancap-kun committed Mar 26, 2023
1 parent c06e516 commit 1a4dffb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Artifex/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>Artifex</artifactId>
<name>Artifex</name>
<version>1.6.17</version>
<version>1.6.18</version>
<description>AncapAPI runtime part</description>
<build>
<finalName>artifex-v${version}</finalName>
Expand Down
2 changes: 1 addition & 1 deletion Artifex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<packaging>jar</packaging>

<artifactId>Artifex</artifactId>
<version>1.6.17</version>
<version>1.6.18</version>

<name>Artifex</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,51 @@ static PathDatabase configuration(JavaPlugin plugin) {
@Nullable List<String> readStrings(String path);
@Nullable Set<String> readKeys(String path);

default List<String> readStrings(String path, boolean safe) {
default List<String> readStrings(String path, boolean nullIsEmpty) {
List<String> strings = this.readStrings(path);
if (strings == null && safe) strings = List.of();
if (strings == null && nullIsEmpty) strings = List.of();
return strings;
}

default Set<String> readKeys(String path, boolean safe) {
default Set<String> readKeys(String path, boolean nullIsEmpty) {
Set<String> keys = this.readKeys(path);
if (keys == null && safe) keys = Set.of();
if (keys == null && nullIsEmpty) keys = Set.of();
return keys;
}

boolean isSet(String path);

default void add(String path, String value) {
List<String> retrieved = this.readStrings(path);
this.add(path, value, false);
}

default void add(String path, String value, boolean nullIsEmpty) {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
if (retrieved == null) throw new IllegalStateException("Tried to add to null section");
List<String> list = new ArrayList<>(retrieved);
list.add(value);
this.write(path, list);
}

default void remove(String path, String value) {
this.remove(path, value, false);
}

default void remove(String path, String value) throws NoSuchElementException {
List<String> retrieved = this.readStrings(path);
default void remove(String path, String value, boolean nullIsEmpty) throws NoSuchElementException {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
if (retrieved == null) throw new IllegalStateException("Tried to remove from null section");
if (!this.contains(path, value)) throw new NoSuchElementException();
List<String> list = new ArrayList<>(retrieved);
list.remove(value);
this.write(path, list);
}

default boolean contains(String path, String value) {
List<String> retrieved = this.readStrings(path);
return this.contains(path, value, false);
}

default boolean contains(String path, String value, boolean nullIsEmpty) {
List<String> retrieved = this.readStrings(path, nullIsEmpty);
if (retrieved == null) throw new IllegalStateException("Tried to get information about null section");
return retrieved.stream()
.anyMatch(s -> s.equals(value));
Expand Down

0 comments on commit 1a4dffb

Please sign in to comment.