Skip to content

Commit

Permalink
0.2.3.
Browse files Browse the repository at this point in the history
 * Added `keys()` method.
 * Made `containsSection(String)` now support tested for nested sections by changing the signature to `containsSection(String...)`.
  • Loading branch information
brett-smith committed Nov 29, 2023
1 parent 75a4d91 commit 6e4302e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ And for writing an INI document ..

```

## Changes

### 0.2.4

* Added `keys()` method.
* Made `containsSection(String)` now support tested for nested sections by changing the signature to `containsSection(String...)`.

## Credits

Uses [LinkedCaseInsensitiveMap](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/LinkedCaseInsensitiveMap.html) from Spring Utilities.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sshtools</groupId>
<artifactId>jini</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<name>Simple Json Configuration</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
37 changes: 33 additions & 4 deletions src/main/java/com/sshtools/jini/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
Expand Down Expand Up @@ -74,11 +75,31 @@ public boolean contains(String key) {
}

@Override
public boolean containsSection(String key) {
return sections.containsKey(key);
public boolean containsSection(String... key) {
if(key.length == 0)
throw new IllegalArgumentException();
else if(key.length == 1)
return sections.containsKey(key[0]);
else {
var section = this;
for(var k : key) {
if(section.sections.containsKey(k)) {
section = section.sections.get(k)[0];
}
else {
return false;
}
}
return true;
}
}

@Override
public Set<String> keys() {
return values.keySet();
}

@Override
public void putAll(String key, String... values) {
this.values.put(key, nullCheck(values));
}
Expand Down Expand Up @@ -214,6 +235,13 @@ private String[] nullCheck(String... objs) {
}
}

/**
* Get an unmodifiable set of the underlying keys.
*
* @return map of keys in this section or document
*/
Set<String> keys();

/**
* Get an unmodifiable map of the underlying values. The returned array of values
* will never be <code>null</code>, but may potentially be an empty array.
Expand Down Expand Up @@ -261,12 +289,13 @@ default Section section(String... path) {
boolean remove(String key);

/**
* Get whether this document or section contains a child section.
* Get whether this document or section contains a child section. Nested sections
* may be specified by provided each path element.
*
* @param key key of section
* @return document or section contains section
*/
boolean containsSection(String key);
boolean containsSection(String... key);

/**
* Put a string value into this document or section with the given key. Any existing
Expand Down

0 comments on commit 6e4302e

Please sign in to comment.