From 83b034a7f5cfc072c6e1fdd9faa966f59a07189e Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 26 May 2025 13:57:42 +0300 Subject: [PATCH 01/27] add eo-yaml --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 6817037..725094b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,11 @@ 21 + + com.amihaiemil.web + eo-yaml + 8.0.6 + org.glassfish jakarta.json From 12b38c98942f776a9a04ea76cf354989d702a514 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 26 May 2025 13:58:02 +0300 Subject: [PATCH 02/27] add ESplit --- .../artemget/entrys/operation/ESplit.java | 82 +++++++++++++++++++ .../entrys/operation/package-info.java | 28 +++++++ 2 files changed, 110 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/operation/ESplit.java create mode 100644 src/main/java/io/github/artemget/entrys/operation/package-info.java diff --git a/src/main/java/io/github/artemget/entrys/operation/ESplit.java b/src/main/java/io/github/artemget/entrys/operation/ESplit.java new file mode 100644 index 0000000..b7ab90f --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/operation/ESplit.java @@ -0,0 +1,82 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.Entry; +import io.github.artemget.entrys.EntryException; +import java.util.Set; +import java.util.regex.PatternSyntaxException; + +/** + * Split entry. + * @since 0.0.2 + */ +public final class ESplit implements Entry> { + /** + * Origin string entry. + */ + private final Entry origin; + + /** + * Split delimiter. + */ + private final String delimiter; + + /** + * Creates split entry with default ; delimiter. + * @param origin Entry + */ + public ESplit(final Entry origin) { + this(origin, ";"); + } + + /** + * Main ctor. + * @param origin Entry + * @param delimiter For splitting + */ + public ESplit(final Entry origin, final String delimiter) { + this.origin = new ESafe<>(origin); + this.delimiter = delimiter; + } + + @Override + public Set value() throws EntryException { + final String value = this.origin.value(); + try { + return Set.of(value.split(this.delimiter)); + } catch (final PatternSyntaxException exception) { + throw new EntryException( + String.format( + "Wrong pattern delimiter: %s for entry value: %s", + this.delimiter, + value + ), + exception + ); + } + } +} diff --git a/src/main/java/io/github/artemget/entrys/operation/package-info.java b/src/main/java/io/github/artemget/entrys/operation/package-info.java new file mode 100644 index 0000000..70c2c96 --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/operation/package-info.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Entry operation directory. + */ +package io.github.artemget.entrys.operation; From 09c45b68f76da47e5d66bd2458111a771d06a704 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 26 May 2025 13:58:13 +0300 Subject: [PATCH 03/27] add EFile --- .../io/github/artemget/entrys/file/EFile.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/file/EFile.java diff --git a/src/main/java/io/github/artemget/entrys/file/EFile.java b/src/main/java/io/github/artemget/entrys/file/EFile.java new file mode 100644 index 0000000..659a98b --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/file/EFile.java @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.file; + +import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.EntryException; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +public class EFile extends ESafe { + public EFile(final String path) { + this(path, StandardCharsets.UTF_8); + } + + public EFile(final String path, final Charset charset) { + super( + () -> { + try { + return Files.readString(Path.of(path), charset); + } catch (final IOException | SecurityException exception) { + throw new EntryException( + String.format( + "Failed to load contents of file for path: '%s'", + path + ), + exception + ); + } + }, + () -> String.format("Empty file for path: '%s'", path) + ); + } +} From 5a84c67ac3ec3e233ff001666fd0ea736b26f114 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 26 May 2025 13:58:29 +0300 Subject: [PATCH 04/27] add temp EVal --- .../io/github/artemget/entrys/file/EVal.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/file/EVal.java diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java new file mode 100644 index 0000000..d500cc1 --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.file; + +import com.amihaiemil.eoyaml.Yaml; +import com.amihaiemil.eoyaml.YamlMapping; +import io.github.artemget.entrys.ESafe; +import java.io.IOException; + +public final class EVal extends ESafe { + + public EVal(final String key) { + this(key, "/src/main/resources/application.yaml"); + } + + public EVal(final String key, final String path) { + super( + () -> { + YamlMapping root; + try { + root = Yaml.createYamlInput(new EFile(path).value()) + .readYamlMapping(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + }, + () -> String.format("Attribute for key '%s' is null for path '%s'", key, path) + ); + } +} From c716140cf3adf25da4c0b70b831b26668c928966 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 6 Jun 2025 16:36:10 +0300 Subject: [PATCH 05/27] remove provided --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 725094b..decee28 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,6 @@ org.cactoos cactoos 0.57.0 - provided org.hamcrest From 1e25b82d717909cfa2f4e83559c70b50822d5bb5 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 6 Jun 2025 16:36:41 +0300 Subject: [PATCH 06/27] add pattern quote in ESplit --- .../java/io/github/artemget/entrys/operation/ESplit.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/operation/ESplit.java b/src/main/java/io/github/artemget/entrys/operation/ESplit.java index b7ab90f..b8e3634 100644 --- a/src/main/java/io/github/artemget/entrys/operation/ESplit.java +++ b/src/main/java/io/github/artemget/entrys/operation/ESplit.java @@ -27,14 +27,16 @@ import io.github.artemget.entrys.ESafe; import io.github.artemget.entrys.Entry; import io.github.artemget.entrys.EntryException; +import java.util.List; import java.util.Set; +import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; /** * Split entry. * @since 0.0.2 */ -public final class ESplit implements Entry> { +public final class ESplit implements Entry> { /** * Origin string entry. */ @@ -64,10 +66,10 @@ public ESplit(final Entry origin, final String delimiter) { } @Override - public Set value() throws EntryException { + public List value() throws EntryException { final String value = this.origin.value(); try { - return Set.of(value.split(this.delimiter)); + return List.of(value.split(Pattern.quote(this.delimiter))); } catch (final PatternSyntaxException exception) { throw new EntryException( String.format( From 7ca4692958c7eadcea442b14ede79ee3ea6a0332 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 6 Jun 2025 16:37:16 +0300 Subject: [PATCH 07/27] temp implementation of EVal --- .../io/github/artemget/entrys/file/EVal.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index d500cc1..4299ac4 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -27,12 +27,15 @@ import com.amihaiemil.eoyaml.Yaml; import com.amihaiemil.eoyaml.YamlMapping; import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.EntryException; +import io.github.artemget.entrys.operation.ESplit; import java.io.IOException; +import java.util.List; public final class EVal extends ESafe { public EVal(final String key) { - this(key, "/src/main/resources/application.yaml"); + this(key, "src/main/resources/application.yaml"); } public EVal(final String key, final String path) { @@ -42,10 +45,25 @@ public EVal(final String key, final String path) { try { root = Yaml.createYamlInput(new EFile(path).value()) .readYamlMapping(); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException exception) { + throw new EntryException( + String.format( + "Failed to read yaml mapping for key: '%s', for path: '%s'", + key, + path + ), + exception + ); } - + String res = null; + List elements = new ESplit(() -> key, ".").value(); + for (int i = 0; i < elements.size(); i++) { + if (i == elements.size() - 1) { + res = root.string(elements.get(i)); + } + root = root.yamlMapping(elements.get(i)); + } + return res; }, () -> String.format("Attribute for key '%s' is null for path '%s'", key, path) ); From 7435c32d7517e793082b06714e8441bc5ac426be Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:16:43 +0300 Subject: [PATCH 08/27] add tests --- .../artemget/entrys/file/package-info.java | 28 +++ .../github/artemget/entrys/file/EValTest.java | 175 ++++++++++++++++++ .../artemget/entrys/file/package-info.java | 28 +++ 3 files changed, 231 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/file/package-info.java create mode 100644 src/test/java/io/github/artemget/entrys/file/EValTest.java create mode 100644 src/test/java/io/github/artemget/entrys/file/package-info.java diff --git a/src/main/java/io/github/artemget/entrys/file/package-info.java b/src/main/java/io/github/artemget/entrys/file/package-info.java new file mode 100644 index 0000000..63f8894 --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/file/package-info.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Entries that read stuff from files. + */ +package io.github.artemget.entrys.file; diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java new file mode 100644 index 0000000..a31b4d0 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -0,0 +1,175 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.file; + +import io.github.artemget.entrys.EntryException; +import io.github.artemget.entrys.fake.EFake; +import io.github.artemget.entrys.fake.EFakeErr; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test cases for {@link io.github.artemget.entrys.json.EJsonArr}. + * @since 0.0.1 + */ +@SuppressWarnings("PMD.AvoidDuplicateLiterals") +final class EValTest { + + @Test + void throwsAtEmptyContent() { + Assertions.assertThrows( + EntryException.class, + () -> new EVal("abc", new EFakeErr<>()).value(), + "Didnt throw at error getting content" + ); + } + + @Test + void parsesString() throws EntryException { + Assertions.assertEquals( + new EVal("age", new EFake<>("age: \"123\"")).value(), + "123", + "String not parsed" + ); + } + + @Test + void parsesInteger() throws EntryException { + Assertions.assertEquals( + Integer.parseInt( + new EVal("age", new EFake<>(String.format("age: %s", Integer.MAX_VALUE))).value() + ), + Integer.MAX_VALUE, + "Integer not parsed" + ); + } + + @Test + void parsesLong() throws EntryException { + Assertions.assertEquals( + Long.parseLong( + new EVal("age", new EFake<>(String.format("age: %s", Long.MAX_VALUE))).value() + ), + Long.MAX_VALUE, + "Long not parsed" + ); + } + + @Test + void parsesFloat() throws EntryException { + Assertions.assertEquals( + Float.parseFloat( + new EVal("age", new EFake<>(String.format("age: %s", Float.MAX_VALUE))).value() + ), + Float.MAX_VALUE, + "Float not parsed" + ); + } + + @Test + void parsesBoolean() throws EntryException { + Assertions.assertTrue( + Boolean.parseBoolean(new EVal("age", new EFake<>("age: true")).value()), + "Boolean not parsed" + ); + } + + @Test + void throwsAtNullValue() { + Assertions.assertThrows( + EntryException.class, + () -> new EVal("age", new EFake<>("age: null")).value(), + "Didnt throw at null value" + ); + } + + @Test + void throwsAtNullAttribute() { + Assertions.assertThrows( + EntryException.class, + () -> new EVal("age", new EFake<>("age2: null")).value(), + "Didnt throw at null value" + ); + } + + @Test + void parsesInnerNode() throws EntryException { + Assertions.assertEquals( + new EVal( + "person.age", + new EFake<>( + """ + person: + age: "123" + """ + ) + ).value(), + "123", + "Inner node not parsed" + ); + } + + @Test + void parsesArray() throws EntryException { + Assertions.assertEquals( + "[123, 321]", + new EVal( + "ages", + new EFake<>( + "ages: [ 123, 321 ]" + ) + ).value(), + "Inner node not parsed" + ); + } + + @Test + void parsesArraya() throws EntryException { + System.out.println(new EVal( + "ages", + new EFake<>( + """ + ages: + - 123 + - 321 + """ + ) + ).value()); + Assertions.assertEquals( + new EVal( + "ages", + new EFake<>( + """ + ages: + - 123 + - 321 + """ + ) + ).value(), + "123", + "Inner node not parsed" + ); + } +} diff --git a/src/test/java/io/github/artemget/entrys/file/package-info.java b/src/test/java/io/github/artemget/entrys/file/package-info.java new file mode 100644 index 0000000..9821934 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/file/package-info.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Tests for entries that read stuff from files. + */ +package io.github.artemget.entrys.file; From 89952a075ffd5ba14af9e141bf22f8e49e308083 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:17:07 +0300 Subject: [PATCH 09/27] add sequence flow --- .../io/github/artemget/entrys/file/EVal.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index 4299ac4..fbba989 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -26,7 +26,9 @@ import com.amihaiemil.eoyaml.Yaml; import com.amihaiemil.eoyaml.YamlMapping; +import com.amihaiemil.eoyaml.YamlNode; import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.Entry; import io.github.artemget.entrys.EntryException; import io.github.artemget.entrys.operation.ESplit; import java.io.IOException; @@ -39,33 +41,34 @@ public EVal(final String key) { } public EVal(final String key, final String path) { + this(key, new EFile(path)); + } + + public EVal(final String key, final Entry content) { super( () -> { YamlMapping root; try { - root = Yaml.createYamlInput(new EFile(path).value()) + root = Yaml.createYamlInput(content.value()) .readYamlMapping(); - } catch (IOException exception) { - throw new EntryException( - String.format( - "Failed to read yaml mapping for key: '%s', for path: '%s'", - key, - path - ), - exception - ); + } catch (IOException | EntryException exception) { + throw new EntryException(String.format("Failed to read yaml mapping for key: '%s'", key), exception); } String res = null; List elements = new ESplit(() -> key, ".").value(); for (int i = 0; i < elements.size(); i++) { if (i == elements.size() - 1) { - res = root.string(elements.get(i)); + final YamlNode value = root.value(elements.get(i)); + switch (value.type()) { + case SCALAR -> res = value.toString(); + case SEQUENCE -> res = value.asSequence().toString(); + } } root = root.yamlMapping(elements.get(i)); } return res; }, - () -> String.format("Attribute for key '%s' is null for path '%s'", key, path) + () -> String.format("Attribute for key '%s' is null", key) ); } } From 6cf551fb382ee848be22ddc07b20a461048f8830 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:36:15 +0300 Subject: [PATCH 10/27] reformat tests --- .../java/io/github/artemget/entrys/file/EValTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index a31b4d0..5ddfa15 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -49,8 +49,8 @@ void throwsAtEmptyContent() { @Test void parsesString() throws EntryException { Assertions.assertEquals( - new EVal("age", new EFake<>("age: \"123\"")).value(), "123", + new EVal("age", new EFake<>("age: \"123\"")).value(), "String not parsed" ); } @@ -58,10 +58,10 @@ void parsesString() throws EntryException { @Test void parsesInteger() throws EntryException { Assertions.assertEquals( + Integer.MAX_VALUE, Integer.parseInt( new EVal("age", new EFake<>(String.format("age: %s", Integer.MAX_VALUE))).value() ), - Integer.MAX_VALUE, "Integer not parsed" ); } @@ -69,10 +69,10 @@ void parsesInteger() throws EntryException { @Test void parsesLong() throws EntryException { Assertions.assertEquals( + Long.MAX_VALUE, Long.parseLong( new EVal("age", new EFake<>(String.format("age: %s", Long.MAX_VALUE))).value() ), - Long.MAX_VALUE, "Long not parsed" ); } @@ -80,10 +80,10 @@ void parsesLong() throws EntryException { @Test void parsesFloat() throws EntryException { Assertions.assertEquals( + Float.MAX_VALUE, Float.parseFloat( new EVal("age", new EFake<>(String.format("age: %s", Float.MAX_VALUE))).value() ), - Float.MAX_VALUE, "Float not parsed" ); } @@ -117,6 +117,7 @@ void throwsAtNullAttribute() { @Test void parsesInnerNode() throws EntryException { Assertions.assertEquals( + "123", new EVal( "person.age", new EFake<>( @@ -126,7 +127,6 @@ void parsesInnerNode() throws EntryException { """ ) ).value(), - "123", "Inner node not parsed" ); } From 11ea217893114b11d650f2f1d9a8f224bea37bca Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:36:32 +0300 Subject: [PATCH 11/27] fixed scalar mapping --- src/main/java/io/github/artemget/entrys/file/EVal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index fbba989..1df47f9 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -60,7 +60,7 @@ public EVal(final String key, final Entry content) { if (i == elements.size() - 1) { final YamlNode value = root.value(elements.get(i)); switch (value.type()) { - case SCALAR -> res = value.toString(); + case SCALAR -> res = value.asScalar().value(); case SEQUENCE -> res = value.asSequence().toString(); } } From a52d8ed64713ea2eb385395332e1dc0600c05ff0 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:40:03 +0300 Subject: [PATCH 12/27] fixed sequence mapping --- .../io/github/artemget/entrys/file/EVal.java | 8 ++++++-- .../io/github/artemget/entrys/file/EValTest.java | 16 +++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index 1df47f9..6c98c29 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -33,6 +33,7 @@ import io.github.artemget.entrys.operation.ESplit; import java.io.IOException; import java.util.List; +import java.util.stream.Collectors; public final class EVal extends ESafe { @@ -60,8 +61,11 @@ public EVal(final String key, final Entry content) { if (i == elements.size() - 1) { final YamlNode value = root.value(elements.get(i)); switch (value.type()) { - case SCALAR -> res = value.asScalar().value(); - case SEQUENCE -> res = value.asSequence().toString(); + case SCALAR -> res = value.asScalar().value(); + case SEQUENCE -> res = value.asSequence() + .children().stream() + .map(node -> node.asScalar().value()) + .collect(Collectors.joining(";")); } } root = root.yamlMapping(elements.get(i)); diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index 5ddfa15..b2d3be8 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -134,7 +134,7 @@ void parsesInnerNode() throws EntryException { @Test void parsesArray() throws EntryException { Assertions.assertEquals( - "[123, 321]", + "123;321", new EVal( "ages", new EFake<>( @@ -146,18 +146,9 @@ void parsesArray() throws EntryException { } @Test - void parsesArraya() throws EntryException { - System.out.println(new EVal( - "ages", - new EFake<>( - """ - ages: - - 123 - - 321 - """ - ) - ).value()); + void parsesAnotherArray() throws EntryException { Assertions.assertEquals( + "123;321", new EVal( "ages", new EFake<>( @@ -168,7 +159,6 @@ void parsesArraya() throws EntryException { """ ) ).value(), - "123", "Inner node not parsed" ); } From b34a442106f68b885b439137bad4c9b0f1b78dfa Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 00:50:57 +0300 Subject: [PATCH 13/27] add tests --- .../github/artemget/entrys/file/EValTest.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index b2d3be8..86298b8 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -141,7 +141,21 @@ void parsesArray() throws EntryException { "ages: [ 123, 321 ]" ) ).value(), - "Inner node not parsed" + "Array node not parsed" + ); + } + + @Test + void parsesEmptyArray() throws EntryException { + Assertions.assertEquals( + "", + new EVal( + "ages", + new EFake<>( + "ages: []" + ) + ).value(), + "Empty array not parsed" ); } @@ -159,7 +173,21 @@ void parsesAnotherArray() throws EntryException { """ ) ).value(), - "Inner node not parsed" + "Array not parsed" + ); + } + + @Test + void parsesStringWrap() throws EntryException { + Assertions.assertEquals( + " First line.\n Second line.\n", + new EVal( + "description", + new EFake<>( + "description: >\n First line.\n Second line." + ) + ).value(), + "String wrap not parsed" ); } } From f682afd911202349f4ccb45481c5dc42dc7e4f61 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:13:13 +0300 Subject: [PATCH 14/27] add unwrap --- .../artemget/entrys/operation/EUnwrap.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/operation/EUnwrap.java diff --git a/src/main/java/io/github/artemget/entrys/operation/EUnwrap.java b/src/main/java/io/github/artemget/entrys/operation/EUnwrap.java new file mode 100644 index 0000000..dd6a88f --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/operation/EUnwrap.java @@ -0,0 +1,98 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.Entry; +import io.github.artemget.entrys.EntryException; + +/** + * Unwraps value between prefix and suffix. + * + * @since 0.4.0 + */ +public final class EUnwrap implements Entry { + /** + * Origin entry. + */ + private final Entry origin; + + /** + * Ctor with default '{}' wraps. + * + * @param value String itself + */ + public EUnwrap(final String value) { + this(value, "{", "}"); + } + + /** + * Ctor with custom suffix and prefix. + * + * @param value String itself + * @param prefix Of string + * @param suffix Of string + */ + public EUnwrap(final String value, final String prefix, final String suffix) { + this( + new ESafe<>( + () -> { + final String unwrapped; + try { + final int start = value.indexOf(prefix) + prefix.length(); + unwrapped = value.substring( + start, + value.indexOf(suffix, start) + ); + } catch (final IndexOutOfBoundsException exception) { + throw new EntryException( + String.format( + "Failed to unwrap value:'%s' with prefix:'%s' and suffix:'%s'", + value, + prefix, + suffix + ), + exception + ); + } + return unwrapped; + } + ) + ); + } + + /** + * Main ctor. + * @param origin Entry + */ + private EUnwrap(final Entry origin) { + this.origin = origin; + } + + @Override + public String value() throws EntryException { + return this.origin.value(); + } +} From 9af844ef9bca5c0de146bc175b5ffc46cec17520 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:13:20 +0300 Subject: [PATCH 15/27] add unwrap tests --- .../entrys/operation/EUnwrapTest.java | 81 +++++++++++++++++++ .../entrys/operation/package-info.java | 28 +++++++ 2 files changed, 109 insertions(+) create mode 100644 src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java create mode 100644 src/test/java/io/github/artemget/entrys/operation/package-info.java diff --git a/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java b/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java new file mode 100644 index 0000000..35983d3 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java @@ -0,0 +1,81 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.EntryException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test cases for {@link EUnwrap}. + * @since 0.4.0 + */ +class EUnwrapTest { + + @Test + void unwraps() throws EntryException { + Assertions.assertEquals( + "123", + new EUnwrap("{123}").value(), + "Not unwrap value with default wraps" + ); + } + + @Test + void unwrapsNotDefault() throws EntryException { + Assertions.assertEquals( + "123", + new EUnwrap("${123}", "${","}").value(), + "Not unwrap value with custom wraps" + ); + } + + @Test + void unwrapsInside() throws EntryException { + Assertions.assertEquals( + "123", + new EUnwrap("blah-blah${123}blah-blah", "${","}").value(), + "Not unwrap value with custom wraps inside bigger string" + ); + } + + @Test + void unwrapsFirst() throws EntryException { + Assertions.assertEquals( + "123", + new EUnwrap("${123}${321}", "${","}").value(), + "Not unwrap first value with custom wraps inside bigger string" + ); + } + + @Test + void unwrapsNotWithoutWraps() { + Assertions.assertThrows( + EntryException.class, + () -> new EUnwrap("123").value(), + "Not thrown at value without wraps" + ); + } +} diff --git a/src/test/java/io/github/artemget/entrys/operation/package-info.java b/src/test/java/io/github/artemget/entrys/operation/package-info.java new file mode 100644 index 0000000..7507994 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/operation/package-info.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Test cases for entry operations. + */ +package io.github.artemget.entrys.operation; From d2a9614978a297ba0893b663853b91e6b41aba4d Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:18:23 +0300 Subject: [PATCH 16/27] add entry contains --- .../artemget/entrys/operation/EContains.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/operation/EContains.java diff --git a/src/main/java/io/github/artemget/entrys/operation/EContains.java b/src/main/java/io/github/artemget/entrys/operation/EContains.java new file mode 100644 index 0000000..f6c97c7 --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/operation/EContains.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.Entry; +import io.github.artemget.entrys.EntryException; + +/** + * Returns either entry is empty or not. + * + * @since 0.4.0 + */ +public final class EContains implements Entry { + /** + * Origin entry. + */ + private final Entry entry; + + /** + * Main ctor. + * + * @param entry To check + */ + public EContains(final Entry entry) { + this.entry = new ESafe<>(entry); + } + + @Override + public Boolean value() throws EntryException { + boolean contains = true; + try { + this.entry.value(); + } catch (final EntryException exception) { + contains = false; + } + return contains; + } +} From 64d7d637ab4b780d327c9b2dcf70fb667fef17d9 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:18:29 +0300 Subject: [PATCH 17/27] add entry contains tests --- .../entrys/operation/EContainsTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/java/io/github/artemget/entrys/operation/EContainsTest.java diff --git a/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java b/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java new file mode 100644 index 0000000..23caf86 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java @@ -0,0 +1,62 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.EntryException; +import io.github.artemget.entrys.fake.EFake; +import io.github.artemget.entrys.fake.EFakeErr; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test cases for {@link EContains}. + * @since 0.4.0 + */ +class EContainsTest { + + @Test + void contains() throws EntryException { + Assertions.assertTrue( + new EContains(new EFake<>("123")).value(), + "Not contains" + ); + } + + @Test + void containsNot() throws EntryException { + Assertions.assertFalse( + new EContains(new EFakeErr<>()).value(), + "Contains" + ); + } + + @Test + void containsNotWhenNull() throws EntryException { + Assertions.assertFalse( + new EContains(new EFake<>(null)).value(), + "Contains" + ); + } +} From 0098f282d179e60e078183c9249b728356a03512 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:21:55 +0300 Subject: [PATCH 18/27] add entry fork --- .../artemget/entrys/operation/EFork.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/io/github/artemget/entrys/operation/EFork.java diff --git a/src/main/java/io/github/artemget/entrys/operation/EFork.java b/src/main/java/io/github/artemget/entrys/operation/EFork.java new file mode 100644 index 0000000..3ef7491 --- /dev/null +++ b/src/main/java/io/github/artemget/entrys/operation/EFork.java @@ -0,0 +1,72 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.Entry; +import io.github.artemget.entrys.EntryException; + +/** + * Fork between origin and spare entries. + * + * @param Type + */ +public final class EFork implements Entry { + /** + * Condition. + */ + private final Entry condition; + + /** + * Origin entry. + */ + private final Entry origin; + + /** + * Spare entry + */ + private final Entry spare; + + /** + * Main ctor. + * + * @param condition To check + * @param origin Entry + * @param spare Entry + */ + public EFork(final Entry condition, final Entry origin, final Entry spare) { + this.condition = condition; + this.origin = origin; + this.spare = spare; + } + + @Override + public T value() throws EntryException { + if (this.condition.value()) { + return this.origin.value(); + } else { + return this.spare.value(); + } + } +} From b42f85c16defadac90dcfc36195103667ef6443a Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:22:00 +0300 Subject: [PATCH 19/27] add entry fork tests --- .../artemget/entrys/operation/EForkTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/java/io/github/artemget/entrys/operation/EForkTest.java diff --git a/src/test/java/io/github/artemget/entrys/operation/EForkTest.java b/src/test/java/io/github/artemget/entrys/operation/EForkTest.java new file mode 100644 index 0000000..a5c9125 --- /dev/null +++ b/src/test/java/io/github/artemget/entrys/operation/EForkTest.java @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (c) 2024-2025. Artem Getmanskii + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.artemget.entrys.operation; + +import io.github.artemget.entrys.EntryException; +import io.github.artemget.entrys.fake.EFake; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test cases for {@link EFork}. + * @since 0.4.0 + */ +class EForkTest { + + @Test + void returnsOrigin() throws EntryException { + Assertions.assertEquals( + "123", + new EFork<>( + () -> true, + new EFake<>("123"), + new EFake<>("321") + ).value(), + "Returned spare" + ); + } + + @Test + void returnsSpare() throws EntryException { + Assertions.assertEquals( + "321", + new EFork<>( + () -> false, + new EFake<>("123"), + new EFake<>("321") + ).value(), + "Returned origin" + ); + } +} \ No newline at end of file From 062edfb93e856de9842eb664e38a1bb6af3b4e82 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:50:46 +0300 Subject: [PATCH 20/27] add lazy to env --- .../java/io/github/artemget/entrys/system/EEnv.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/system/EEnv.java b/src/main/java/io/github/artemget/entrys/system/EEnv.java index c3bbb4f..6a426f6 100644 --- a/src/main/java/io/github/artemget/entrys/system/EEnv.java +++ b/src/main/java/io/github/artemget/entrys/system/EEnv.java @@ -25,6 +25,7 @@ package io.github.artemget.entrys.system; import io.github.artemget.entrys.ESafe; +import io.github.artemget.entrys.Entry; /** * Environment entry. @@ -32,13 +33,21 @@ */ public final class EEnv extends ESafe { + /** + * Entry ctor. + * @param name Entry + */ + public EEnv(final String name) { + this(() -> name); + } + /** * Main ctor. * @param name Of environment entry */ - public EEnv(final String name) { + public EEnv(final Entry name) { super( - () -> System.getenv(name), + () -> System.getenv(name.value()), () -> String.format("Empty environment entry for name %s", name) ); } From 1880767ec608a82eda0e88d73a3702063dcd58ad Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 14:51:27 +0300 Subject: [PATCH 21/27] add env ejection to EVal --- .../io/github/artemget/entrys/file/EVal.java | 30 +++++++++++++++++-- .../github/artemget/entrys/file/EValTest.java | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index 6c98c29..85001bc 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -30,7 +30,11 @@ import io.github.artemget.entrys.ESafe; import io.github.artemget.entrys.Entry; import io.github.artemget.entrys.EntryException; +import io.github.artemget.entrys.operation.EContains; +import io.github.artemget.entrys.operation.EFork; import io.github.artemget.entrys.operation.ESplit; +import io.github.artemget.entrys.operation.EUnwrap; +import io.github.artemget.entrys.system.EEnv; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -56,12 +60,12 @@ public EVal(final String key, final Entry content) { throw new EntryException(String.format("Failed to read yaml mapping for key: '%s'", key), exception); } String res = null; - List elements = new ESplit(() -> key, ".").value(); + final List elements = new ESplit(() -> key, ".").value(); for (int i = 0; i < elements.size(); i++) { if (i == elements.size() - 1) { final YamlNode value = root.value(elements.get(i)); switch (value.type()) { - case SCALAR -> res = value.asScalar().value(); + case SCALAR -> res = EVal.ejected(value); case SEQUENCE -> res = value.asSequence() .children().stream() .map(node -> node.asScalar().value()) @@ -75,4 +79,26 @@ public EVal(final String key, final Entry content) { () -> String.format("Attribute for key '%s' is null", key) ); } + + private static String ejected(final YamlNode node) throws EntryException { + final String scalar = node.asScalar().value(); + return new EFork<>( + () -> scalar.startsWith("${") && scalar.endsWith("}"), + new EFork<>( + () -> new ESplit(() -> scalar, ":").value().size() == 2, + new EFork<>( + new EContains(new EEnv(new EUnwrap(scalar, "${", "}"))), + new EEnv(() -> EVal.selected(scalar, 1)), + () -> EVal.selected(scalar, 2) + ), + new EEnv(new EUnwrap(scalar, "${", "}")) + ), + () -> scalar + ).value(); + } + + private static String selected(final String scalar, final int pos) throws EntryException { + return new ESplit(new EUnwrap(scalar, "${", "}"), ":") + .value().get(pos); + } } diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index 86298b8..896c01c 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -32,7 +32,7 @@ /** * Test cases for {@link io.github.artemget.entrys.json.EJsonArr}. - * @since 0.0.1 + * @since 0.4.0 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") final class EValTest { From 5eb84ceb42223536598331ec212a10267805539a Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 15:07:55 +0300 Subject: [PATCH 22/27] add env ejection tests --- .../github/artemget/entrys/file/EValTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index 896c01c..1b76d72 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -29,6 +29,7 @@ import io.github.artemget.entrys.fake.EFakeErr; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; /** * Test cases for {@link io.github.artemget.entrys.json.EJsonArr}. @@ -190,4 +191,40 @@ void parsesStringWrap() throws EntryException { "String wrap not parsed" ); } + + @Test + void parsesDefaultValueAtMissingEnv() throws EntryException { + Assertions.assertEquals( + "123", + new EVal( + "age", + new EFake<>( + "age: ${my_env:123}" + ) + ).value(), + "Not parsed default value" + ); + } + + @Test + void parsesEnv() throws Exception { + Assertions.assertEquals( + "321", + new EnvironmentVariables("my_env", "321").execute( + () -> new EVal("age", new EFake<>("age: ${my_env}")).value() + ), + "Not parsed default value" + ); + } + + @Test + void parsesEnvOverwritesDefaultValue() throws Exception { + Assertions.assertEquals( + "111", + new EnvironmentVariables("my_env", "111").execute( + () -> new EVal("age", new EFake<>("age: ${my_env:123}")).value() + ), + "Not parsed default value" + ); + } } From 65d6f8a5c4f01ada91c41aed63f39ba7ca144a68 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 15:08:49 +0300 Subject: [PATCH 23/27] fixed EVal --- src/main/java/io/github/artemget/entrys/file/EVal.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index 85001bc..a668cc8 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -87,9 +87,9 @@ private static String ejected(final YamlNode node) throws EntryException { new EFork<>( () -> new ESplit(() -> scalar, ":").value().size() == 2, new EFork<>( - new EContains(new EEnv(new EUnwrap(scalar, "${", "}"))), - new EEnv(() -> EVal.selected(scalar, 1)), - () -> EVal.selected(scalar, 2) + new EContains(new EEnv(() -> EVal.selected(scalar, 0).trim())), + new EEnv(() -> EVal.selected(scalar, 0).trim()), + () -> EVal.selected(scalar, 1).trim() ), new EEnv(new EUnwrap(scalar, "${", "}")) ), From cdc3f147e67747c53ca06a0fea3c5e2e5d3e51fa Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 15:32:58 +0300 Subject: [PATCH 24/27] fixed checkstyle --- .../io/github/artemget/entrys/file/EFile.java | 5 ++ .../io/github/artemget/entrys/file/EVal.java | 48 +++++++++++++++---- .../artemget/entrys/operation/EFork.java | 9 ++-- .../artemget/entrys/operation/ESplit.java | 1 - .../github/artemget/entrys/file/EValTest.java | 28 ++--------- .../entrys/operation/EContainsTest.java | 2 +- .../artemget/entrys/operation/EForkTest.java | 4 +- .../entrys/operation/EUnwrapTest.java | 9 ++-- 8 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/main/java/io/github/artemget/entrys/file/EFile.java b/src/main/java/io/github/artemget/entrys/file/EFile.java index 659a98b..b2a7b7c 100644 --- a/src/main/java/io/github/artemget/entrys/file/EFile.java +++ b/src/main/java/io/github/artemget/entrys/file/EFile.java @@ -32,6 +32,11 @@ import java.nio.file.Files; import java.nio.file.Path; +/** + * File's content entry. + * + * @since 0.4.0 + */ public class EFile extends ESafe { public EFile(final String path) { this(path, StandardCharsets.UTF_8); diff --git a/src/main/java/io/github/artemget/entrys/file/EVal.java b/src/main/java/io/github/artemget/entrys/file/EVal.java index a668cc8..a6e131d 100644 --- a/src/main/java/io/github/artemget/entrys/file/EVal.java +++ b/src/main/java/io/github/artemget/entrys/file/EVal.java @@ -24,6 +24,7 @@ package io.github.artemget.entrys.file; +import com.amihaiemil.eoyaml.Node; import com.amihaiemil.eoyaml.Yaml; import com.amihaiemil.eoyaml.YamlMapping; import com.amihaiemil.eoyaml.YamlNode; @@ -39,16 +40,41 @@ import java.util.List; import java.util.stream.Collectors; +/** + * Configuration properties entry. + * By default gets entries from "src/main/resources/application.yaml" + * Supports all yaml types, default values and envs passed via ${ENV}. + * + * @since 0.4.0 + */ public final class EVal extends ESafe { + /** + * From yaml file at default dir. + * + * @param key Of entry + */ public EVal(final String key) { this(key, "src/main/resources/application.yaml"); } + /** + * From yaml file. + * + * @param key Of entry + * @param path To yaml file + */ public EVal(final String key, final String path) { this(key, new EFile(path)); } + /** + * Main ctor. + * + * @param key Of Entry + * @param content Yaml content + */ + @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") public EVal(final String key, final Entry content) { super( () -> { @@ -56,23 +82,27 @@ public EVal(final String key, final Entry content) { try { root = Yaml.createYamlInput(content.value()) .readYamlMapping(); - } catch (IOException | EntryException exception) { - throw new EntryException(String.format("Failed to read yaml mapping for key: '%s'", key), exception); + } catch (final IOException | EntryException exception) { + throw new EntryException( + String.format("Failed to read yaml mapping for key: '%s'", key), + exception + ); } String res = null; final List elements = new ESplit(() -> key, ".").value(); - for (int i = 0; i < elements.size(); i++) { - if (i == elements.size() - 1) { - final YamlNode value = root.value(elements.get(i)); - switch (value.type()) { - case SCALAR -> res = EVal.ejected(value); - case SEQUENCE -> res = value.asSequence() + for (int element = 0; element < elements.size(); ++element) { + if (element == elements.size() - 1) { + final YamlNode value = root.value(elements.get(element)); + if (Node.SCALAR == value.type()) { + res = EVal.ejected(value); + } else if (Node.SEQUENCE == value.type()) { + res = value.asSequence() .children().stream() .map(node -> node.asScalar().value()) .collect(Collectors.joining(";")); } } - root = root.yamlMapping(elements.get(i)); + root = root.yamlMapping(elements.get(element)); } return res; }, diff --git a/src/main/java/io/github/artemget/entrys/operation/EFork.java b/src/main/java/io/github/artemget/entrys/operation/EFork.java index 3ef7491..a28ae8c 100644 --- a/src/main/java/io/github/artemget/entrys/operation/EFork.java +++ b/src/main/java/io/github/artemget/entrys/operation/EFork.java @@ -31,6 +31,7 @@ * Fork between origin and spare entries. * * @param Type + * @since 0.4.0 */ public final class EFork implements Entry { /** @@ -44,7 +45,7 @@ public final class EFork implements Entry { private final Entry origin; /** - * Spare entry + * Spare entry. */ private final Entry spare; @@ -63,10 +64,12 @@ public EFork(final Entry condition, final Entry origin, final Entry< @Override public T value() throws EntryException { + final T value; if (this.condition.value()) { - return this.origin.value(); + value = this.origin.value(); } else { - return this.spare.value(); + value = this.spare.value(); } + return value; } } diff --git a/src/main/java/io/github/artemget/entrys/operation/ESplit.java b/src/main/java/io/github/artemget/entrys/operation/ESplit.java index b8e3634..bb8ccdd 100644 --- a/src/main/java/io/github/artemget/entrys/operation/ESplit.java +++ b/src/main/java/io/github/artemget/entrys/operation/ESplit.java @@ -28,7 +28,6 @@ import io.github.artemget.entrys.Entry; import io.github.artemget.entrys.EntryException; import java.util.List; -import java.util.Set; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; diff --git a/src/test/java/io/github/artemget/entrys/file/EValTest.java b/src/test/java/io/github/artemget/entrys/file/EValTest.java index 1b76d72..7e221eb 100644 --- a/src/test/java/io/github/artemget/entrys/file/EValTest.java +++ b/src/test/java/io/github/artemget/entrys/file/EValTest.java @@ -35,7 +35,7 @@ * Test cases for {@link io.github.artemget.entrys.json.EJsonArr}. * @since 0.4.0 */ -@SuppressWarnings("PMD.AvoidDuplicateLiterals") +@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"}) final class EValTest { @Test @@ -121,12 +121,7 @@ void parsesInnerNode() throws EntryException { "123", new EVal( "person.age", - new EFake<>( - """ - person: - age: "123" - """ - ) + new EFake<>("person:\n age: \"123\"") ).value(), "Inner node not parsed" ); @@ -136,12 +131,7 @@ void parsesInnerNode() throws EntryException { void parsesArray() throws EntryException { Assertions.assertEquals( "123;321", - new EVal( - "ages", - new EFake<>( - "ages: [ 123, 321 ]" - ) - ).value(), + new EVal("ages", new EFake<>("ages: [ 123, 321 ]")).value(), "Array node not parsed" ); } @@ -166,13 +156,7 @@ void parsesAnotherArray() throws EntryException { "123;321", new EVal( "ages", - new EFake<>( - """ - ages: - - 123 - - 321 - """ - ) + new EFake<>("ages:\n - 123\n - 321") ).value(), "Array not parsed" ); @@ -184,9 +168,7 @@ void parsesStringWrap() throws EntryException { " First line.\n Second line.\n", new EVal( "description", - new EFake<>( - "description: >\n First line.\n Second line." - ) + new EFake<>("description: >\n First line.\n Second line.") ).value(), "String wrap not parsed" ); diff --git a/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java b/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java index 23caf86..7f28ffc 100644 --- a/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java +++ b/src/test/java/io/github/artemget/entrys/operation/EContainsTest.java @@ -34,7 +34,7 @@ * Test cases for {@link EContains}. * @since 0.4.0 */ -class EContainsTest { +final class EContainsTest { @Test void contains() throws EntryException { diff --git a/src/test/java/io/github/artemget/entrys/operation/EForkTest.java b/src/test/java/io/github/artemget/entrys/operation/EForkTest.java index a5c9125..e3a97e8 100644 --- a/src/test/java/io/github/artemget/entrys/operation/EForkTest.java +++ b/src/test/java/io/github/artemget/entrys/operation/EForkTest.java @@ -33,7 +33,7 @@ * Test cases for {@link EFork}. * @since 0.4.0 */ -class EForkTest { +final class EForkTest { @Test void returnsOrigin() throws EntryException { @@ -60,4 +60,4 @@ void returnsSpare() throws EntryException { "Returned origin" ); } -} \ No newline at end of file +} diff --git a/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java b/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java index 35983d3..2ee21ca 100644 --- a/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java +++ b/src/test/java/io/github/artemget/entrys/operation/EUnwrapTest.java @@ -32,7 +32,8 @@ * Test cases for {@link EUnwrap}. * @since 0.4.0 */ -class EUnwrapTest { +@SuppressWarnings("PMD.AvoidDuplicateLiterals") +final class EUnwrapTest { @Test void unwraps() throws EntryException { @@ -47,7 +48,7 @@ void unwraps() throws EntryException { void unwrapsNotDefault() throws EntryException { Assertions.assertEquals( "123", - new EUnwrap("${123}", "${","}").value(), + new EUnwrap("${123}", "${", "}").value(), "Not unwrap value with custom wraps" ); } @@ -56,7 +57,7 @@ void unwrapsNotDefault() throws EntryException { void unwrapsInside() throws EntryException { Assertions.assertEquals( "123", - new EUnwrap("blah-blah${123}blah-blah", "${","}").value(), + new EUnwrap("blah-blah${123}blah-blah", "${", "}").value(), "Not unwrap value with custom wraps inside bigger string" ); } @@ -65,7 +66,7 @@ void unwrapsInside() throws EntryException { void unwrapsFirst() throws EntryException { Assertions.assertEquals( "123", - new EUnwrap("${123}${321}", "${","}").value(), + new EUnwrap("${123}${321}", "${", "}").value(), "Not unwrap first value with custom wraps inside bigger string" ); } From f1f5d07015018645f00ddb91b9fccd74067b73ec Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 15:35:18 +0300 Subject: [PATCH 25/27] exclude duplicate dep --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index decee28..12158d5 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,12 @@ com.amihaiemil.web eo-yaml 8.0.6 + + + javax.json + javax.json-api + + org.glassfish From ff31de51204906a68aeb1581b69767d04e817a8d Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 15:59:29 +0300 Subject: [PATCH 26/27] add docs --- README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bb04ba8..54f0fcf 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,84 @@ # Overview -Library designed for retrieving properties set at application startup. +Library designed for retrieving properties set at application startup. If you don't use Spring Framework/Spring Boot but +like its configuration via yaml - you will find this library useful. + +# Advantages + +1) Lightweight, no need to pull lots of dependencies +2) No reflection and typecasts +3) Null safe and runtime exception free # Quick start + This library is distributed via [jitpack.io](https://jitpack.io/#ArtemGet/entrys) -# Supported properties +# Supported entries + 1) Properties passed via -D -2) Json files (strings, objects, arrays) +2) Environment variables +3) Json strings +4) Yaml files + +# Examples + +## Properties: + +```java +String prop=new EProp("your_prop_passed_via_-D").value(); +``` + +## Environment variables: + +```java +String env=new EEnv("my_env").value() +``` + +## Json strings: + +TODO add docs + +## Yaml files: + +1) Works similar to spring + framework [@Value](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Value.html) +2) Supports string, number, arrays, float, boolean as value +3) Supports default values and env injections +4) Default yaml file config is placed under "src/main/resources/application.yaml", but is configurable + +```yaml +sex: "male" +person: + name: "kekus" + languages: [ ru,en ] + age: ${AGE_ENV:123} +``` + +#### Getting attribute: + +```java +String sex=new EVal("sex").value(); +``` + +#### Getting nested attribute: + +```java +String name=new EVal("person.name").value(); +``` + +#### Getting array + +```java +List languages=new ESplit(new EVal("person.languages")).value(); +``` + +#### Getting env + +```java +String age=new EVal("person.age").value(); +``` -TODO: -1) Environment variables -2) Yaml files -3) Properties files +1) If there is a default value and env is not present - will return default value +2) If there is a default value and env is present - will return value from env +3) If default value is not present - will return value from env From d70ba859c320985af289d4a39d704efb952a0ba6 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sat, 28 Jun 2025 16:02:33 +0300 Subject: [PATCH 27/27] fix v --- src/main/java/io/github/artemget/entrys/operation/ESplit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/artemget/entrys/operation/ESplit.java b/src/main/java/io/github/artemget/entrys/operation/ESplit.java index bb8ccdd..ec26284 100644 --- a/src/main/java/io/github/artemget/entrys/operation/ESplit.java +++ b/src/main/java/io/github/artemget/entrys/operation/ESplit.java @@ -33,7 +33,7 @@ /** * Split entry. - * @since 0.0.2 + * @since 0.4.0 */ public final class ESplit implements Entry> { /**