Add support for Instant, File, Path, URL, and URI

dev
Exlll 2 years ago
parent 5216a889af
commit 31748db01b

@ -14,7 +14,9 @@ the [Tutorial](https://github.com/Exlll/ConfigLib/wiki/Tutorial) page on the wik
* Automatic creation, saving, loading, and updating of configuration files
* Support for comments through annotations
* Support for all primitive types, their wrapper types, and Strings
* Support for `BigInteger`, `BigDecimal`, `LocalDate`, `LocalTime`, `LocalDateTime`, and `UUID`
* Support for `BigInteger` and `BigDecimal`
* Support for `LocalDate`, `LocalTime`, `LocalDateTime`, and `Instant`
* Support for `UUID`, `File`, `Path`, `URL`, and `URI`
* Support for (nested) lists, sets, arrays, and maps
* Support for enums and POJOs (+ inheritance!)
* Support for Bukkit's `ConfigurationSerializable` types (e.g. `ItemStack`)
@ -34,7 +36,7 @@ of this documentation.
For a step-by-step tutorial with a more advanced example check out
the [Tutorial](https://github.com/Exlll/ConfigLib/wiki/Tutorial) page on the wiki.
If you want support Bukkit classes like `ItemStack`, check out
If you want support for Bukkit classes like `ItemStack`, check out
the [Configuration properties](#configuration-properties) section.
```java
@ -122,7 +124,7 @@ Two things are noticeable here:
1. Not every user in the `blockedUsers` list has a `password` mapping. This is because null values
are not output by default. That behavior can be changed by the builder.
2. The password of the user with username `user3` that has no comment. This is due to limitations of
2. The password of the user with username `user3` has no comment. This is due to limitations of
the YAML library. Configurations in lists, sets, or maps cannot have their comments printed.
## General information
@ -154,8 +156,8 @@ A configuration type may only contain fields of the following types:
| Floating point types | `float`, `double`, and their respective wrapper types |
| Characters and strings | `char`, `Character`, `String` |
| Big numeric types | `BigInteger`, `BigDecimal` |
| Time related types | `LocalTime`, `LocalDate`, `LocalDateTime` |
| Utility types | `UUID` |
| Time related types | `LocalTime`, `LocalDate`, `LocalDateTime`, `Instant` |
| Utility types | `UUID`, `File`, `Path`, `URL`, `URI` |
| Enums | Any Java enum |
| Configurations | Any configuration type |
| `ConfigurationSerializable` | All Bukkit classes that implement this interface, like `ItemStack` |
@ -610,4 +612,4 @@ details.
- Post load / pre save hooks
- TOML support
- Change the order of fields in parent/child class scenarios
- Recursive definitions
- Recursive definitions

@ -2,9 +2,14 @@ package de.exlll.configlib;
import de.exlll.configlib.Serializers.*;
import java.io.File;
import java.lang.reflect.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -35,7 +40,12 @@ final class SerializerSelector {
Map.entry(LocalDate.class, new LocalDateSerializer()),
Map.entry(LocalTime.class, new LocalTimeSerializer()),
Map.entry(LocalDateTime.class, new LocalDateTimeSerializer()),
Map.entry(UUID.class, new UuidSerializer())
Map.entry(Instant.class, new InstantSerializer()),
Map.entry(UUID.class, new UuidSerializer()),
Map.entry(File.class, new FileSerializer()),
Map.entry(Path.class, new PathSerializer()),
Map.entry(URL.class, new UrlSerializer()),
Map.entry(URI.class, new UriSerializer())
);
private final ConfigurationProperties properties;
@ -67,7 +77,7 @@ final class SerializerSelector {
private Serializer<?, ?> selectCustomSerializer(Type type) {
if (type instanceof Class<?> cls) {
if (properties.getSerializers().containsKey(cls)) // TODO move check out
if (properties.getSerializers().containsKey(cls))
return properties.getSerializers().get(cls);
}
for (var entry : properties.getSerializersByCondition().entrySet()) {

@ -1,7 +1,13 @@
package de.exlll.configlib;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -241,6 +247,18 @@ final class Serializers {
}
}
static final class InstantSerializer implements Serializer<Instant, String> {
@Override
public String serialize(Instant element) {
return element.toString();
}
@Override
public Instant deserialize(String element) {
return Instant.parse(element);
}
}
static final class UuidSerializer implements Serializer<UUID, String> {
@Override
public String serialize(UUID element) {
@ -253,6 +271,58 @@ final class Serializers {
}
}
static final class FileSerializer implements Serializer<File, String> {
@Override
public String serialize(File element) {
return element.toString();
}
@Override
public File deserialize(String element) {
return new File(element);
}
}
static final class PathSerializer implements Serializer<Path, String> {
@Override
public String serialize(Path element) {
return element.toString();
}
@Override
public Path deserialize(String element) {
return Path.of(element);
}
}
static final class UrlSerializer implements Serializer<URL, String> {
@Override
public String serialize(URL element) {
return element.toString();
}
@Override
public URL deserialize(String element) {
try {
return new URL(element);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
static final class UriSerializer implements Serializer<URI, String> {
@Override
public String serialize(URI element) {
return element.toString();
}
@Override
public URI deserialize(String element) {
return URI.create(element);
}
}
static final class EnumSerializer implements Serializer<Enum<?>, String> {
private final Class<? extends Enum<?>> cls;

@ -272,6 +272,12 @@ class ExampleConfigurationTests {
assertThat(a1_1.getA1_localDate(), is(a1_2.getA1_localDate()));
assertThat(a1_1.getA1_localTime(), is(a1_2.getA1_localTime()));
assertThat(a1_1.getA1_localDateTime(), is(a1_2.getA1_localDateTime()));
assertThat(a1_1.getA1_instant(), is(a1_2.getA1_instant()));
assertThat(a1_1.getA1_uuid(), is(a1_2.getA1_uuid()));
assertThat(a1_1.getA1_file(), is(a1_2.getA1_file()));
assertThat(a1_1.getA1_path(), is(a1_2.getA1_path()));
assertThat(a1_1.getA1_url(), is(a1_2.getA1_url()));
assertThat(a1_1.getA1_uri(), is(a1_2.getA1_uri()));
assertThat(a1_1.getA1_uuid(), is(a1_2.getA1_uuid()));
assertThat(a1_1.getA1_Enm(), is(a1_2.getA1_Enm()));
assertThat(a1_1.getA1_b1(), is(a1_2.getA1_b1()));
@ -290,7 +296,12 @@ class ExampleConfigurationTests {
assertThat(a1_1.getA1_listLocalDate(), is(a1_2.getA1_listLocalDate()));
assertThat(a1_1.getA1_listLocalTime(), is(a1_2.getA1_listLocalTime()));
assertThat(a1_1.getA1_listLocalDateTime(), is(a1_2.getA1_listLocalDateTime()));
assertThat(a1_1.getA1_listInstant(), is(a1_2.getA1_listInstant()));
assertThat(a1_1.getA1_listUuid(), is(a1_2.getA1_listUuid()));
assertThat(a1_1.getA1_listFile(), is(a1_2.getA1_listFile()));
assertThat(a1_1.getA1_listPath(), is(a1_2.getA1_listPath()));
assertThat(a1_1.getA1_listUrl(), is(a1_2.getA1_listUrl()));
assertThat(a1_1.getA1_listUri(), is(a1_2.getA1_listUri()));
assertThat(a1_1.getA1_listEnm(), is(a1_2.getA1_listEnm()));
assertThat(a1_1.getA1_listB1(), is(a1_2.getA1_listB1()));
assertThat(a1_1.getA1_listB2(), is(a1_2.getA1_listB2()));
@ -443,7 +454,12 @@ class ExampleConfigurationTests {
assertThat(a2_1.getA2_localDate(), is(a2_2.getA2_localDate()));
assertThat(a2_1.getA2_localTime(), is(a2_2.getA2_localTime()));
assertThat(a2_1.getA2_localDateTime(), is(a2_2.getA2_localDateTime()));
assertThat(a2_1.getA2_instant(), is(a2_2.getA2_instant()));
assertThat(a2_1.getA2_uuid(), is(a2_2.getA2_uuid()));
assertThat(a2_1.getA2_file(), is(a2_2.getA2_file()));
assertThat(a2_1.getA2_path(), is(a2_2.getA2_path()));
assertThat(a2_1.getA2_url(), is(a2_2.getA2_url()));
assertThat(a2_1.getA2_uri(), is(a2_2.getA2_uri()));
assertThat(a2_1.getA2_Enm(), is(a2_2.getA2_Enm()));
assertThat(a2_1.getA2_b1(), is(a2_2.getA2_b1()));
assertThat(a2_1.getA2_b2(), is(a2_2.getA2_b2()));
@ -461,7 +477,12 @@ class ExampleConfigurationTests {
assertThat(a2_1.getA2_listLocalDate(), is(a2_2.getA2_listLocalDate()));
assertThat(a2_1.getA2_listLocalTime(), is(a2_2.getA2_listLocalTime()));
assertThat(a2_1.getA2_listLocalDateTime(), is(a2_2.getA2_listLocalDateTime()));
assertThat(a2_1.getA2_listInstant(), is(a2_2.getA2_listInstant()));
assertThat(a2_1.getA2_listUuid(), is(a2_2.getA2_listUuid()));
assertThat(a2_1.getA2_listFile(), is(a2_2.getA2_listFile()));
assertThat(a2_1.getA2_listPath(), is(a2_2.getA2_listPath()));
assertThat(a2_1.getA2_listUrl(), is(a2_2.getA2_listUrl()));
assertThat(a2_1.getA2_listUri(), is(a2_2.getA2_listUri()));
assertThat(a2_1.getA2_listEnm(), is(a2_2.getA2_listEnm()));
assertThat(a2_1.getA2_listB1(), is(a2_2.getA2_listB1()));
assertThat(a2_1.getA2_listB2(), is(a2_2.getA2_listB2()));

@ -6,11 +6,16 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.awt.Point;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -94,12 +99,42 @@ class SerializerSelectorTest {
assertThat(serializer, instanceOf(LocalDateTimeSerializer.class));
}
@Test
void selectSerializerInstant() {
Serializer<?, ?> serializer = SELECTOR.select(Instant.class);
assertThat(serializer, instanceOf(InstantSerializer.class));
}
@Test
void selectSerializerUuid() {
Serializer<?, ?> serializer = SELECTOR.select(UUID.class);
assertThat(serializer, instanceOf(UuidSerializer.class));
}
@Test
void selectSerializerFile() {
Serializer<?, ?> serializer = SELECTOR.select(File.class);
assertThat(serializer, instanceOf(FileSerializer.class));
}
@Test
void selectSerializerPath() {
Serializer<?, ?> serializer = SELECTOR.select(Path.class);
assertThat(serializer, instanceOf(PathSerializer.class));
}
@Test
void selectSerializerUrl() {
Serializer<?, ?> serializer = SELECTOR.select(URL.class);
assertThat(serializer, instanceOf(UrlSerializer.class));
}
@Test
void selectSerializerUri() {
Serializer<?, ?> serializer = SELECTOR.select(URI.class);
assertThat(serializer, instanceOf(UriSerializer.class));
}
@Test
void selectSerializerEnum() {
enum E {}

@ -9,12 +9,13 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
@ -429,6 +430,18 @@ class SerializersTest {
assertThat(serializer.deserialize("2000-02-29T10:11:12"), is(dateTime));
}
@Test
void instantSerializer() {
Serializer<Instant, String> serializer = new Serializers.InstantSerializer();
Instant instant = LocalDateTime.of(2000, Month.FEBRUARY, 29, 10, 11, 12, 13)
.toInstant(ZoneOffset.UTC);
assertThat(serializer.serialize(instant), is("2000-02-29T10:11:12.000000013Z"));
assertThat(serializer.deserialize("2000-02-29T10:11:12.000000013Z"), is(instant));
}
@Test
void uuidSerializer() {
Serializer<UUID, String> serializer = new Serializers.UuidSerializer();
@ -443,6 +456,90 @@ class SerializersTest {
assertThat(uuid, is(deserialized));
}
@Test
void fileSerializer() {
Serializer<File, String> serializer = new Serializers.FileSerializer();
String path1 = "/tmp/config.yml";
String path2 = "/tmp/with \n new \n lines.yml";
String path3 = "/tmp";
File file1 = new File(path1);
File file2 = new File(path2);
File file3 = new File(path3);
assertThat(serializer.serialize(file1), is(path1));
assertThat(serializer.serialize(file2), is(path2));
assertThat(serializer.serialize(file3), is(path3));
assertThat(serializer.deserialize(path1), is(file1));
assertThat(serializer.deserialize(path2), is(file2));
assertThat(serializer.deserialize(path3), is(file3));
}
@Test
void pathSerializer() {
Serializer<Path, String> serializer = new Serializers.PathSerializer();
String path1 = "/tmp/config.yml";
String path2 = "/tmp/with \n new \n lines.yml";
String path3 = "/tmp";
Path file1 = Path.of(path1);
Path file2 = Path.of(path2);
Path file3 = Path.of(path3);
assertThat(serializer.serialize(file1), is(path1));
assertThat(serializer.serialize(file2), is(path2));
assertThat(serializer.serialize(file3), is(path3));
assertThat(serializer.deserialize(path1), is(file1));
assertThat(serializer.deserialize(path2), is(file2));
assertThat(serializer.deserialize(path3), is(file3));
}
@Test
void urlSerializer() throws Exception {
Serializer<URL, String> serializer = new Serializers.UrlSerializer();
String path1 = "https://example.com";
String path2 = "https://example.com?query=yes";
String path3 = "https://example.com?query=yes#fragment=true";
URL url1 = new URL(path1);
URL url2 = new URL(path2);
URL url3 = new URL(path3);
assertThat(serializer.serialize(url1), is(path1));
assertThat(serializer.serialize(url2), is(path2));
assertThat(serializer.serialize(url3), is(path3));
assertThat(serializer.deserialize(path1), is(url1));
assertThat(serializer.deserialize(path2), is(url2));
assertThat(serializer.deserialize(path3), is(url3));
}
@Test
void uriSerializer() {
Serializer<URI, String> serializer = new Serializers.UriSerializer();
String path1 = "https://example.com";
String path2 = "https://example.com?query=yes";
String path3 = "https://example.com?query=yes#fragment=true";
URI uri1 = URI.create(path1);
URI uri2 = URI.create(path2);
URI uri3 = URI.create(path3);
assertThat(serializer.serialize(uri1), is(path1));
assertThat(serializer.serialize(uri2), is(path2));
assertThat(serializer.serialize(uri3), is(path3));
assertThat(serializer.deserialize(path1), is(uri1));
assertThat(serializer.deserialize(path2), is(uri2));
assertThat(serializer.deserialize(path3), is(uri3));
}
enum E {X, Y, Z}
@ParameterizedTest

@ -4,8 +4,13 @@ import de.exlll.configlib.Configuration;
import de.exlll.configlib.Ignore;
import java.awt.Point;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -56,7 +61,12 @@ public class ExampleConfigurationA1 {
private LocalDate a1_localDate;
private LocalTime a1_localTime;
private LocalDateTime a1_localDateTime;
private Instant a1_instant;
private UUID a1_uuid;
private File a1_file;
private Path a1_path;
private URL a1_url;
private URI a1_uri;
private ExampleEnum a1_Enm;
/* OTHER CONFIGURATIONS */
@ -78,7 +88,12 @@ public class ExampleConfigurationA1 {
private List<LocalDate> a1_listLocalDate;
private List<LocalTime> a1_listLocalTime;
private List<LocalDateTime> a1_listLocalDateTime;
private List<Instant> a1_listInstant;
private List<UUID> a1_listUuid;
private List<File> a1_listFile;
private List<Path> a1_listPath;
private List<URL> a1_listUrl;
private List<URI> a1_listUri;
private List<ExampleEnum> a1_listEnm;
private List<ExampleConfigurationB1> a1_listB1;
private List<ExampleConfigurationB2> a1_listB2;
@ -1470,4 +1485,84 @@ public class ExampleConfigurationA1 {
public void setA1_arrayArrayUuid(UUID[][] a1_arrayArrayUuid) {
this.a1_arrayArrayUuid = a1_arrayArrayUuid;
}
public Instant getA1_instant() {
return a1_instant;
}
public void setA1_instant(Instant a1_instant) {
this.a1_instant = a1_instant;
}
public File getA1_file() {
return a1_file;
}
public void setA1_file(File a1_file) {
this.a1_file = a1_file;
}
public Path getA1_path() {
return a1_path;
}
public void setA1_path(Path a1_path) {
this.a1_path = a1_path;
}
public URL getA1_url() {
return a1_url;
}
public void setA1_url(URL a1_url) {
this.a1_url = a1_url;
}
public URI getA1_uri() {
return a1_uri;
}
public void setA1_uri(URI a1_uri) {
this.a1_uri = a1_uri;
}
public List<Instant> getA1_listInstant() {
return a1_listInstant;
}
public void setA1_listInstant(List<Instant> a1_listInstant) {
this.a1_listInstant = a1_listInstant;
}
public List<File> getA1_listFile() {
return a1_listFile;
}
public void setA1_listFile(List<File> a1_listFile) {
this.a1_listFile = a1_listFile;
}
public List<Path> getA1_listPath() {
return a1_listPath;
}
public void setA1_listPath(List<Path> a1_listPath) {
this.a1_listPath = a1_listPath;
}
public List<URL> getA1_listUrl() {
return a1_listUrl;
}
public void setA1_listUrl(List<URL> a1_listUrl) {
this.a1_listUrl = a1_listUrl;
}
public List<URI> getA1_listUri() {
return a1_listUri;
}
public void setA1_listUri(List<URI> a1_listUri) {
this.a1_listUri = a1_listUri;
}
}

@ -3,8 +3,13 @@ package de.exlll.configlib.configurations;
import de.exlll.configlib.Ignore;
import java.awt.Point;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -54,7 +59,12 @@ public final class ExampleConfigurationA2 extends ExampleConfigurationA1 {
private LocalDate a2_localDate;
private LocalTime a2_localTime;
private LocalDateTime a2_localDateTime;
private Instant a2_instant;
private UUID a2_uuid;
private File a2_file;
private Path a2_path;
private URL a2_url;
private URI a2_uri;
private ExampleEnum a2_Enm;
/* OTHER CONFIGURATIONS */
@ -76,7 +86,12 @@ public final class ExampleConfigurationA2 extends ExampleConfigurationA1 {
private List<LocalDate> a2_listLocalDate;
private List<LocalTime> a2_listLocalTime;
private List<LocalDateTime> a2_listLocalDateTime;
private List<Instant> a2_listInstant;
private List<UUID> a2_listUuid;
private List<File> a2_listFile;
private List<Path> a2_listPath;
private List<URL> a2_listUrl;
private List<URI> a2_listUri;
private List<ExampleEnum> a2_listEnm;
private List<ExampleConfigurationB1> a2_listB1;
private List<ExampleConfigurationB2> a2_listB2;
@ -1502,4 +1517,84 @@ public final class ExampleConfigurationA2 extends ExampleConfigurationA1 {
public void setA2_arrayArrayUuid(UUID[][] a2_arrayArrayUuid) {
this.a2_arrayArrayUuid = a2_arrayArrayUuid;
}
public Instant getA2_instant() {
return a2_instant;
}
public void setA2_instant(Instant a2_instant) {
this.a2_instant = a2_instant;
}
public File getA2_file() {
return a2_file;
}
public void setA2_file(File a2_file) {
this.a2_file = a2_file;
}
public Path getA2_path() {
return a2_path;
}
public void setA2_path(Path a2_path) {
this.a2_path = a2_path;
}
public URL getA2_url() {
return a2_url;
}
public void setA2_url(URL a2_url) {
this.a2_url = a2_url;
}
public URI getA2_uri() {
return a2_uri;
}
public void setA2_uri(URI a2_uri) {
this.a2_uri = a2_uri;
}
public List<Instant> getA2_listInstant() {
return a2_listInstant;
}
public void setA2_listInstant(List<Instant> a2_listInstant) {
this.a2_listInstant = a2_listInstant;
}
public List<File> getA2_listFile() {
return a2_listFile;
}
public void setA2_listFile(List<File> a2_listFile) {
this.a2_listFile = a2_listFile;
}
public List<Path> getA2_listPath() {
return a2_listPath;
}
public void setA2_listPath(List<Path> a2_listPath) {
this.a2_listPath = a2_listPath;
}
public List<URL> getA2_listUrl() {
return a2_listUrl;
}
public void setA2_listUrl(List<URL> a2_listUrl) {
this.a2_listUrl = a2_listUrl;
}
public List<URI> getA2_listUri() {
return a2_listUri;
}
public void setA2_listUri(List<URI> a2_listUri) {
this.a2_listUri = a2_listUri;
}
}

@ -93,7 +93,12 @@ public final class ExampleConfigurationsSerialized {
entry("a1_localDate", "2000-01-01"),
entry("a1_localTime", "00:01"),
entry("a1_localDateTime", "2000-01-01T00:00"),
entry("a1_instant", "0000-01-01T00:00:00Z"),
entry("a1_uuid", "d50f3bdd-ac66-4b74-a01f-4617b24d68c0"),
entry("a1_file", "/tmp"),
entry("a1_path", "/tmp"),
entry("a1_url", "https://example.com"),
entry("a1_uri", "https://example.com"),
entry("a1_Enm", "A"),
entry("a1_b1", EXAMPLE_CONFIGURATION_B1_1),
entry("a1_b2", EXAMPLE_CONFIGURATION_B2_1),
@ -111,7 +116,12 @@ public final class ExampleConfigurationsSerialized {
entry("a1_listLocalDate", List.of("2000-01-01", "2000-01-02", "2000-01-03")),
entry("a1_listLocalTime", List.of("00:01", "00:02", "00:03")),
entry("a1_listLocalDateTime", List.of("2000-01-01T00:00", "2000-01-02T00:00", "2000-01-03T00:00")),
entry("a1_listInstant", List.of("0000-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "-1000000000-01-01T00:00:00Z")),
entry("a1_listUuid", List.of("d50f3bdd-ac66-4b74-a01f-4617b24d68c0", "d50f3bdd-ac66-4b74-a01f-4617b24d68c1", "d50f3bdd-ac66-4b74-a01f-4617b24d68c2")),
entry("a1_listFile", List.of("/tmp", "/tmp/config.yml", "/tmp/with \n new \n lines.yml")),
entry("a1_listPath", List.of("/tmp", "/tmp/config.yml", "/tmp/with \n new \n lines.yml")),
entry("a1_listUrl", List.of("https://example.com", "https://example.com?query=yes", "https://example.com?query=yes#fragment=true")),
entry("a1_listUri", List.of("https://example.com", "https://example.com?query=yes", "https://example.com?query=yes#fragment=true")),
entry("a1_listEnm", List.of("A", "B", "C")),
entry("a1_listB1", List.of(EXAMPLE_CONFIGURATION_B1_1)),
entry("a1_listB2", List.of(EXAMPLE_CONFIGURATION_B2_1)),
@ -249,7 +259,12 @@ public final class ExampleConfigurationsSerialized {
entry("a2_localDate", "2000-01-02"),
entry("a2_localTime", "00:02"),
entry("a2_localDateTime", "2000-01-02T00:00"),
entry("a2_instant", "0001-01-01T00:00:00Z"),
entry("a2_uuid", "d50f3bdd-ac66-4b74-a01f-4617b24d68c1"),
entry("a2_file", "/tmp/config.yml"),
entry("a2_path", "/tmp/config.yml"),
entry("a2_url", "https://example.com?query=yes"),
entry("a2_uri", "https://example.com?query=yes"),
entry("a2_Enm", "B"),
entry("a2_b1", EXAMPLE_CONFIGURATION_B1_2),
entry("a2_b2", EXAMPLE_CONFIGURATION_B2_2),
@ -267,7 +282,12 @@ public final class ExampleConfigurationsSerialized {
entry("a2_listLocalDate", List.of("2000-01-02", "2000-01-03", "2000-01-04")),
entry("a2_listLocalTime", List.of("00:02", "00:03", "00:04")),
entry("a2_listLocalDateTime", List.of("2000-01-02T00:00", "2000-01-03T00:00", "2000-01-04T00:00")),
entry("a2_listInstant", List.of("0001-01-01T00:00:00Z", "-1000000000-01-01T00:00:00Z", "+1000000000-12-31T23:59:59.999999999Z")),
entry("a2_listUuid", List.of("d50f3bdd-ac66-4b74-a01f-4617b24d68c1", "d50f3bdd-ac66-4b74-a01f-4617b24d68c2", "d50f3bdd-ac66-4b74-a01f-4617b24d68c3")),
entry("a2_listFile", List.of("/tmp/config.yml", "/tmp/with \n new \n lines.yml", "with \n new \n lines.yml")),
entry("a2_listPath", List.of("/tmp/config.yml", "/tmp/with \n new \n lines.yml", "with \n new \n lines.yml")),
entry("a2_listUrl", List.of("https://example.com?query=yes", "https://example.com?query=yes#fragment=true", "https://example.com#fragment=true")),
entry("a2_listUri", List.of("https://example.com?query=yes", "https://example.com?query=yes#fragment=true", "https://example.com#fragment=true")),
entry("a2_listEnm", List.of("B", "C", "D")),
entry("a2_listB1", List.of(EXAMPLE_CONFIGURATION_B1_1, EXAMPLE_CONFIGURATION_B1_2)),
entry("a2_listB2", List.of(EXAMPLE_CONFIGURATION_B2_1, EXAMPLE_CONFIGURATION_B2_2)),

@ -1,12 +1,14 @@
package de.exlll.configlib.configurations;
import java.awt.Point;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -46,12 +48,37 @@ public final class ExampleInitializer {
private static final LocalDateTime LDT_4 = LocalDateTime.of(2000, Month.JANUARY, 4, 0, 0);
private static final LocalDateTime LDT_5 = LocalDateTime.of(2000, Month.JANUARY, 5, 0, 0);
private static final Instant INSTANT_1 = Instant.parse("0000-01-01T00:00:00Z");
private static final Instant INSTANT_2 = Instant.parse("0001-01-01T00:00:00Z");
private static final Instant INSTANT_3 = Instant.parse("-1000000000-01-01T00:00:00Z");
private static final Instant INSTANT_4 = Instant.parse("+1000000000-12-31T23:59:59.999999999Z");
private static final UUID UUID_1 = UUID.fromString("d50f3bdd-ac66-4b74-a01f-4617b24d68c0");
private static final UUID UUID_2 = UUID.fromString("d50f3bdd-ac66-4b74-a01f-4617b24d68c1");
private static final UUID UUID_3 = UUID.fromString("d50f3bdd-ac66-4b74-a01f-4617b24d68c2");
private static final UUID UUID_4 = UUID.fromString("d50f3bdd-ac66-4b74-a01f-4617b24d68c3");
private static final UUID UUID_5 = UUID.fromString("d50f3bdd-ac66-4b74-a01f-4617b24d68c4");
private static final File FILE_1 = new File("/tmp");
private static final File FILE_2 = new File("/tmp/config.yml");
private static final File FILE_3 = new File("/tmp/with \n new \n lines.yml");
private static final File FILE_4 = new File("with \n new \n lines.yml");
private static final Path PATH_1 = Path.of("/tmp");
private static final Path PATH_2 = Path.of("/tmp/config.yml");
private static final Path PATH_3 = Path.of("/tmp/with \n new \n lines.yml");
private static final Path PATH_4 = Path.of("with \n new \n lines.yml");
private static final URL URL_1 = createUrl("https://example.com");
private static final URL URL_2 = createUrl("https://example.com?query=yes");
private static final URL URL_3 = createUrl("https://example.com?query=yes#fragment=true");
private static final URL URL_4 = createUrl("https://example.com#fragment=true");
private static final URI URI_1 = URI.create("https://example.com");
private static final URI URI_2 = URI.create("https://example.com?query=yes");
private static final URI URI_3 = URI.create("https://example.com?query=yes#fragment=true");
private static final URI URI_4 = URI.create("https://example.com#fragment=true");
private static final ExampleConfigurationB1 B1_1 = newExampleConfigurationB1_1();
private static final ExampleConfigurationB1 B1_2 = newExampleConfigurationB1_2();
private static final ExampleConfigurationB2 B2_1 = newExampleConfigurationB2_1();
@ -62,6 +89,14 @@ public final class ExampleInitializer {
private static final Point P3 = new Point(0, 3);
private static final Point P4 = new Point(0, 4);
private static URL createUrl(String url) {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public static ExampleConfigurationA2 newExampleConfigurationA2() {
ExampleConfigurationA2 a2 = new ExampleConfigurationA2();
@ -131,9 +166,24 @@ public final class ExampleInitializer {
a2.setA1_localDateTime(LDT_1);
a2.setA2_localDateTime(LDT_2);
a2.setA1_instant(INSTANT_1);
a2.setA2_instant(INSTANT_2);
a2.setA1_uuid(UUID_1);
a2.setA2_uuid(UUID_2);
a2.setA1_file(FILE_1);
a2.setA2_file(FILE_2);
a2.setA1_path(PATH_1);
a2.setA2_path(PATH_2);
a2.setA1_url(URL_1);
a2.setA2_url(URL_2);
a2.setA1_uri(URI_1);
a2.setA2_uri(URI_2);
a2.setA1_Enm(A);
a2.setA2_Enm(B);
@ -185,9 +235,24 @@ public final class ExampleInitializer {
a2.setA1_listLocalDateTime(List.of(LDT_1, LDT_2, LDT_3));
a2.setA2_listLocalDateTime(List.of(LDT_2, LDT_3, LDT_4));
a2.setA1_listInstant(List.of(INSTANT_1, INSTANT_2, INSTANT_3));
a2.setA2_listInstant(List.of(INSTANT_2, INSTANT_3, INSTANT_4));
a2.setA1_listUuid(List.of(UUID_1, UUID_2, UUID_3));
a2.setA2_listUuid(List.of(UUID_2, UUID_3, UUID_4));
a2.setA1_listFile(List.of(FILE_1, FILE_2, FILE_3));
a2.setA2_listFile(List.of(FILE_2, FILE_3, FILE_4));
a2.setA1_listPath(List.of(PATH_1, PATH_2, PATH_3));
a2.setA2_listPath(List.of(PATH_2, PATH_3, PATH_4));
a2.setA1_listUrl(List.of(URL_1, URL_2, URL_3));
a2.setA2_listUrl(List.of(URL_2, URL_3, URL_4));
a2.setA1_listUri(List.of(URI_1, URI_2, URI_3));
a2.setA2_listUri(List.of(URI_2, URI_3, URI_4));
a2.setA1_listEnm(List.of(A, B, C));
a2.setA2_listEnm(List.of(B, C, D));

Loading…
Cancel
Save