diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
deleted file mode 100644
index 786b7ee..0000000
--- a/.github/workflows/codeql-analysis.yml
+++ /dev/null
@@ -1,71 +0,0 @@
-# For most projects, this workflow file will not need changing; you simply need
-# to commit it to your repository.
-#
-# You may wish to alter this file to override the set of languages analyzed,
-# or to provide custom queries or build logic.
-#
-# ******** NOTE ********
-# We have attempted to detect the languages in your repository. Please check
-# the `language` matrix defined below to confirm you have the correct set of
-# supported CodeQL languages.
-#
-name: "CodeQL"
-
-on:
- push:
- branches: [ master ]
- pull_request:
- # The branches below must be a subset of the branches above
- branches: [ master ]
- schedule:
- - cron: '36 12 * * 3'
-
-jobs:
- analyze:
- name: Analyze
- runs-on: ubuntu-latest
- permissions:
- actions: read
- contents: read
- security-events: write
-
- strategy:
- fail-fast: false
- matrix:
- language: [ 'java' ]
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
- # Learn more:
- # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v2
-
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v1
- with:
- languages: ${{ matrix.language }}
- # If you wish to specify custom queries, you can do so here or in a config file.
- # By default, queries listed here will override any specified in a config file.
- # Prefix the list here with "+" to use these queries and those in the config file.
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v1
-
- # âšī¸ Command-line programs to run using the OS shell.
- # đ https://git.io/JvXDl
-
- # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines
- # and modify them (or add more) to build your code if your project
- # uses a compiled language
-
- #- run: |
- # make bootstrap
- # make release
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v1
diff --git a/README.md b/README.md
index ce46d41..33ba121 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,23 @@ It looks better to organize config in a YAML file since it makes sense to mainta
**YamlConfig** helps read configuration for a java project from a YAML config file and access them via dotted notation.
+## â 1.3.0 Breaking changes:
+
+
+Version **1.3.0** introduces breaking changes as follows:
+
+```
+YamlConfig config = YamlConfig.load(resource);
+YamlConfig config = YamlConfig.load(yaml, resource);
+```
+
+is now:
+
+```
+YamlConfig config = new YamlConfig(resource);
+YamlConfig config = new YamlConfig(yaml, resource);
+```
+
## Features
- Uses SnakeYAML for reading YAML, so it can handle any data recognizable by SnakeYAML.
- Ease of access using dotted notation to read properties
@@ -19,13 +36,13 @@ If you use Maven for Dependency management, you can include this using below dep
first.second[2].third
- * @return The String value of property. null if the key is not present
- * or not a leaf node. Boolean or Integer or other format
- * are converted to String.
+ * @param key key in dotted notation like first.second[2].third
+ * @return the String value of property.
+ *
+ * null if the key is not present or not a leaf node.
+ *
+ * Boolean or Integer or another format is converted to String.
*/
public String getString(String key) {
- Object foundNode = getNode(key, content);
+ Object foundNode = getNode(key);
if (foundNode != null && !(foundNode instanceof Collection)) {
return foundNode.toString();
}
@@ -88,45 +80,98 @@ public String getString(String key) {
/**
* Gets the Integer value for the specified key from the config.
*
- * @param key Key in dotted notation like first.second[2].third
- * @return The Integer value of property. null if the key is not present
- * or not a leaf node.
+ * @param key key in dotted notation like first.second[2].third
+ * @return the Integer value of property.
+ *
+ * null if the key is not present or not a leaf node.
*/
public Integer getInt(String key) {
- Object foundNode = getNode(key, content);
- if (foundNode instanceof Integer) {
- return (Integer) foundNode;
+ Object node = getNode(key);
+ if (node instanceof Integer) {
+ return (Integer) node;
+ }
+ return null;
+ }
+
+ /**
+ * Gets a string list for the specified key from the config.
+ *
+ * @param key key in dotted notation like first.second
+ * @return the type list value of property.
+ *
+ *
+ * null if the key is not present or not a leaf node.
+ */
+ public ArrayListfirst.second
+ * @return the generic list.
+ * null if the key is not present or not a leaf node.
+ */
+ public null if not found
+ */
+ private Object getNode(String key) {
+ final String[] parts = splitByDot(key);
+
+ Object node = content;
for (String part : parts) {
int arrayNum = -1;
- Matcher matcher = arrayKeyPattern.matcher(part);
- if (matcher.matches()) {
- part = matcher.group(1);
- arrayNum = Integer.parseInt(matcher.group(2));
+ final Matcher arrayKeyPatternMatcher = arrayKeyPattern.matcher(part);
+ final Matcher keyPatternMatcher = keyPattern.matcher(part);
+ if (arrayKeyPatternMatcher.matches()) {
+ part = arrayKeyPatternMatcher.group(1);
+ arrayNum = Integer.parseInt(arrayKeyPatternMatcher.group(2));
+ } else if (keyPatternMatcher.matches()) {
+ part = keyPatternMatcher.group(1);
}
- if (foundNode instanceof Map) {
- if (((Map, ?>) foundNode).containsKey(part)) {
- foundNode = ((Map, ?>) foundNode).get(part);
+ if (node instanceof Map) {
+ if (((Map, ?>) node).containsKey(part)) {
+ node = ((Map, ?>) node).get(part);
if (arrayNum >= 0) {
- if (foundNode instanceof ArrayList
- && ((ArrayList>) foundNode).size() > arrayNum) {
- foundNode = ((ArrayList>) foundNode).get(arrayNum);
- } else
- return null;
+ if (node instanceof ArrayList> && ((ArrayList>) node).size() > arrayNum) {
+ node = ((ArrayList>) node).get(arrayNum);
+ }
}
- } else
+ } else {
return null;
+ }
}
}
- return foundNode;
+ return node;
}
- private String[] decompose(String key) {
+
+ /**
+ * Splits a key by the dot character.
+ *
+ * @param key The key to split
+ * @return the split key path.
+ */
+ private String[] splitByDot(String key) {
return key.split("\\.");
}
}
diff --git a/src/test/java/com/github/jsixface/YamlConfigTest.java b/src/test/java/com/github/jsixface/YamlConfigTest.java
index a356d21..6f40bc4 100644
--- a/src/test/java/com/github/jsixface/YamlConfigTest.java
+++ b/src/test/java/com/github/jsixface/YamlConfigTest.java
@@ -16,62 +16,68 @@
package com.github.jsixface;
+import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import static org.junit.Assert.*;
public class YamlConfigTest {
private final InputStream resource = getClass().getClassLoader().getResourceAsStream("test.yml");
+ private YamlConfig config;
+
+ @Before
+ public void loadResource() {
+ config = new YamlConfig(resource);
+ assertNotNull(resource);
+ }
@Test
- public void load() {
+ public void getStringList() {
+ final ArrayList