Skip to content

Commit

Permalink
YAMLParser now supports YAML lists not parsed by the parser itself.
Browse files Browse the repository at this point in the history
This means that list of type
```yaml
list:
  - test: "Hello"
  - test: "Hi"
```
will be parsed as a list of (ConfigurationSection)[src/main/java/it/fulminazzo/yamlparser/configuration/ConfigurationSection].
Totally reworked classes separation to respect packaging conventions.
Reworked FileConfiguration#addParsers method.
Reworked `FileConfiguration#newYaml` method to support older versions of SnakeYAML.
Renamed `it.fulminazzo.yamlparser.configurations` package to `it.fulminazzo.yamlparser.configuration`.
Made FileConfiguration and ConfigurationSection final.
Added support for escaped dot characters: now it will be able to use `\.` in paths to allow for dotted strings to be parsed.
Added support for BigDecimal notation when getting Number types.
Added `unquote` method to remove quoted strings when saving or loading.
Added `getOptional` method in IConfiguration.
Added _gui_ formatting in `FileUtils#formatStringToYaml(String)`.
Now IConfiguration extends Serializable.
Removed nullity annotations from **YAMLParser** methods.
Fixed dotted test error.
Fixed `IConfiguration#getKeys` not returning an ordered set.
Fixed NullPointerException in `IConfiguration#throwException` method.
Fixed MapYAMLParser not supporting primitive types.
Fixed `FileConfiguration#getParser` method to look first for equal object classes.
Fixed `CollectionYAMLParser` not returning null values in non-specified indexes.
Updated README.md.
Updated FulmiCollection.
  • Loading branch information
fulminazzo committed Mar 30, 2024
1 parent 1d58012 commit 9def09a
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ In this case, we remove the previous object and stop if the new one is null.
Otherwise, we create the corresponding section and save the desired into it:
```java
@Override
protected TriConsumer<@NotNull IConfiguration, @NotNull String, @NotNull Person> getDumper() {
protected TriConsumer<IConfiguration, String, Person> getDumper() {
return (configuration, path, person) -> {
if (configuration == null || path == null) return;
if (person == null) return;
Expand All @@ -315,7 +315,7 @@ Otherwise, load the name and the age and create a new person with these values (
**It is up to the user to handle any exception accordingly**, for example if age was null):
```java
@Override
protected BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable Person> getLoader() {
protected BiFunctionException<IConfiguration, String, Person> getLoader() {
return (configuration, path) -> {
if (configuration == null || path == null) return null;
ConfigurationSection personSection = configuration.getConfigurationSection(path);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'it.fulminazzo'
version = '1.5.12'
version = '1.5.13'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import it.fulminazzo.fulmicollection.interfaces.functions.BiFunctionException;
import it.fulminazzo.fulmicollection.interfaces.functions.TriConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Array;
import java.util.Arrays;
Expand Down Expand Up @@ -35,7 +34,7 @@ public ArrayYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable T[]> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, T[]> getLoader() {
return (c, s) -> {
List<T> tmp = listYamlParser.load(c, s);
if (tmp == null) return null;
Expand All @@ -53,7 +52,7 @@ public ArrayYAMLParser() {
* @return the dumper
*/
@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @NotNull T[]> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, T[]> getDumper() {
return (c, s, o) -> {
assert o != null;
listYamlParser.dump(c, s, Arrays.asList(o));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import it.fulminazzo.yamlparser.configuration.ConfigurationSection;
import it.fulminazzo.yamlparser.utils.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand All @@ -34,7 +33,7 @@ public CallableYAMLParser(@NotNull Class<T> tClass, FunctionException<Configurat
}

@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable T> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, T> getLoader() {
return (c, s) -> {
ConfigurationSection section = c.getConfigurationSection(s);
if (section == null) return null;
Expand All @@ -52,7 +51,7 @@ public CallableYAMLParser(@NotNull Class<T> tClass, FunctionException<Configurat
}

@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable T> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, T> getDumper() {
return (c, s, t) -> {
c.set(s, null);
if (t == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CollectionYAMLParser(@NotNull Class<C> aClass) {
}

@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable C> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, C> getLoader() {
return (c, s) -> {
if (c.isConfigurationSection(s)) {
@Nullable Map<Integer, T> map = mapYamlParser.load(c, s);
Expand All @@ -47,7 +47,7 @@ public CollectionYAMLParser(@NotNull Class<C> aClass) {
}

@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable C> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, C> getDumper() {
return (c, s, o) -> {
c.set(s, null);
if (o == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.fulminazzo.fulmicollection.interfaces.functions.BiFunctionException;
import it.fulminazzo.fulmicollection.interfaces.functions.TriConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Date;

Expand All @@ -26,7 +25,7 @@ public DateYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable Date> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, Date> getLoader() {
return (c, s) -> {
Long l = c.getLong(s);
return l == null ? null : new Date(l);
Expand All @@ -39,7 +38,7 @@ public DateYAMLParser() {
* @return the dumper
*/
@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable Date> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, Date> getDumper() {
return (c, s, d) -> c.set(s, d == null ? null : d.getTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.fulminazzo.fulmicollection.interfaces.functions.TriConsumer;
import it.fulminazzo.yamlparser.configuration.IConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Enum YAML parser.
Expand All @@ -24,15 +23,15 @@ public EnumYAMLParser(@NotNull Class<?> eClass) {
}

@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable E> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, E> getLoader() {
return (c, s) -> {
String enumString = c.getString(s);
return E.valueOf(getOClass(), enumString);
};
}

@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable E> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, E> getDumper() {
return (c, s, e) -> c.set(s, e == null ? null : e.name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.fulminazzo.yamlparser.configuration.IConfiguration;
import it.fulminazzo.fulmicollection.interfaces.functions.BiFunctionException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -32,15 +31,15 @@ public ListYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable List<T>> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, List<T>> getLoader() {
return (c, s) -> {
Collection<T> loaded = super.getLoader().apply(c, s);
return loaded == null ? null : new ArrayList<>(loaded);
};
}

@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable List<T>> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, List<T>> getDumper() {
return (c, s, o) -> {
if (o != null && !o.isEmpty()) {
Object firstNonNull = o.stream().filter(Objects::nonNull).findFirst().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import it.fulminazzo.yamlparser.configuration.ConfigurationSection;
import it.fulminazzo.yamlparser.configuration.IConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -51,7 +50,7 @@ public MapYAMLParser(Function<String, K> keyLoader, Function<K, String> keyParse
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable Map<K, V>> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, Map<K, V>> getLoader() {
return (c, s) -> {
ConfigurationSection section = c.getConfigurationSection(s);
Class<V> oClass = null;
Expand All @@ -73,7 +72,7 @@ public MapYAMLParser(Function<String, K> keyLoader, Function<K, String> keyParse
* @return the dumper
*/
@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @NotNull Map<K, V>> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, Map<K, V>> getDumper() {
return (c, s, m) -> {
ConfigurationSection section = c.createSection(s);
m.forEach((k, v) -> section.set(keyParser.apply(k), v));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import it.fulminazzo.fulmicollection.interfaces.functions.BiFunctionException;
import it.fulminazzo.fulmicollection.interfaces.functions.TriConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;

Expand All @@ -27,7 +26,7 @@ public SerializableYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable Serializable> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, Serializable> getLoader() {
return (c, s) -> {
try {
String string = (String) c.getObject(s);
Expand All @@ -44,7 +43,7 @@ public SerializableYAMLParser() {
* @return the dumper
*/
@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @NotNull Serializable> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, Serializable> getDumper() {
return (c, s, ser) -> c.set(s, SerializeUtils.serializeToBase64(ser));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SetYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable Set<T>> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, Set<T>> getLoader() {
return (c, s) -> {
@Nullable Collection<T> object = super.getLoader().apply(c, s);
return new HashSet<>(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.fulminazzo.fulmicollection.interfaces.functions.BiFunctionException;
import it.fulminazzo.fulmicollection.interfaces.functions.TriConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

Expand All @@ -26,7 +25,7 @@ public UUIDYAMLParser() {
* @return the loader
*/
@Override
protected @NotNull BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable UUID> getLoader() {
protected @NotNull BiFunctionException<IConfiguration, String, UUID> getLoader() {
return (c, s) -> {
String raw = c.getString(s);
return UUID.fromString(raw);
Expand All @@ -39,7 +38,7 @@ public UUIDYAMLParser() {
* @return the dumper
*/
@Override
protected @NotNull TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable UUID> getDumper() {
protected @NotNull TriConsumer<IConfiguration, String, UUID> getDumper() {
return (c, s, u) -> c.set(s, u == null ? null : u.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public void dump(@Nullable IConfiguration section, @Nullable String path, @Nulla
*
* @return the loader
*/
protected abstract BiFunctionException<@NotNull IConfiguration, @NotNull String, @Nullable O> getLoader();
protected abstract BiFunctionException<IConfiguration, String, O> getLoader();

/**
* Gets dumper.
*
* @return the dumper
*/
protected abstract TriConsumer<@NotNull IConfiguration, @NotNull String, @Nullable O> getDumper();
protected abstract TriConsumer<IConfiguration, String, O> getDumper();

@Override
public boolean equals(Object o) {
Expand Down

0 comments on commit 9def09a

Please sign in to comment.