mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Rename Toml#containsKey() to containsPrimitive
This commit is contained in:
parent
41b5438707
commit
b1436c557d
4 changed files with 13 additions and 12 deletions
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* __BREAKING:__ Toml#parse methods renamed to read
|
||||||
* __BREAKING:__ Toml#getList(String), Toml#getTable(String) and Toml#getTables(String) return null when key is not found
|
* __BREAKING:__ Toml#getList(String), Toml#getTable(String) and Toml#getTables(String) return null when key is not found
|
||||||
* Removed trailing newline from error messages (thanks to __[Zero3](https://github.com/Zero3)__)
|
* Removed trailing newline from error messages (thanks to __[Zero3](https://github.com/Zero3)__)
|
||||||
* __BREAKING:__ Toml#parse methods renamed to read
|
|
||||||
* Toml#read(File) forces encoding to UTF-8 (thanks to __[Bruno Medeiros](https://github.com/bruno-medeiros)__)
|
* Toml#read(File) forces encoding to UTF-8 (thanks to __[Bruno Medeiros](https://github.com/bruno-medeiros)__)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
* Support for underscores in numbers (the feature branch had accidentally not been merged into 0.4.0! :( )
|
* Support for underscores in numbers (the feature branch had accidentally not been merged into 0.4.0! :( )
|
||||||
* Set<Map.Entry> Toml#entrySet() cf. Reflection section in README (thanks __[Zero3](https://github.com/Zero3)__ and __[d3xter](https://github.com/d3xter)__)
|
* Set<Map.Entry> Toml#entrySet() cf. Reflection section in README (thanks __[Zero3](https://github.com/Zero3)__ and __[d3xter](https://github.com/d3xter)__)
|
||||||
* Overloaded getters that take a default value (thanks to __[udiabon](https://github.com/udiabon)__)
|
* Overloaded getters that take a default value (thanks to __[udiabon](https://github.com/udiabon)__)
|
||||||
|
* Toml#contains(String) and Toml#containsXXX(String) methods to check for existence of keys
|
||||||
|
|
||||||
## 0.4.0 / 2015-02-16
|
## 0.4.0 / 2015-02-16
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
toml4j is a [TOML 0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md) parser for Java.
|
toml4j is a [TOML 0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md) parser for Java.
|
||||||
|
|
||||||
[![Maven Central](https://img.shields.io/maven-central/v/com.moandjiezana.toml/toml4j.svg)](https://search.maven.org/#search|gav|1|g%3A%22com.moandjiezana.toml%22%20AND%20a%3A%22toml4j%22) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Build Status](https://travis-ci.org/mwanji/toml4j.svg?branch=wip)](https://travis-ci.org/mwanji/toml4j) [![Coverage Status](https://coveralls.io/repos/mwanji/toml4j/badge.svg?branch=wip)](https://coveralls.io/r/mwanji/toml4j?branch=wip) [![Dependency Status](https://www.versioneye.com/user/projects/558bc2bc653232001e000001/badge.svg?style=flat)](https://www.versioneye.com/user/projects/558bc2bc653232001e000001)
|
[![Maven Central](https://img.shields.io/maven-central/v/com.moandjiezana.toml/toml4j.svg)](https://search.maven.org/#search|gav|1|g%3A%22com.moandjiezana.toml%22%20AND%20a%3A%22toml4j%22) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Build Status](https://travis-ci.org/mwanji/toml4j.svg)](https://travis-ci.org/mwanji/toml4j) [![Coverage Status](https://coveralls.io/repos/mwanji/toml4j/badge.svg)](https://coveralls.io/r/mwanji/toml4j) [![Dependency Status](https://www.versioneye.com/user/projects/558bc2bc653232001e000001/badge.svg?style=flat)](https://www.versioneye.com/user/projects/558bc2bc653232001e000001)
|
||||||
|
|
||||||
For the bleeding-edge version integrating the latest specs, see the [work-in-progress branch](https://github.com/mwanji/toml4j/tree/wip).
|
For the bleeding-edge version integrating the latest specs, see the [work-in-progress branch](https://github.com/mwanji/toml4j/tree/wip).
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ Toml toml = new Toml().parse("a = 1");
|
||||||
Map<String, Object> map = toml.to(Map.class);
|
Map<String, Object> map = toml.to(Map.class);
|
||||||
```
|
```
|
||||||
|
|
||||||
`Toml#contains(String)` verifies that the instance contains a key of any type (primitive, table or array of tables) of the given name. `Toml#containsKey(String)`, `Toml#containsTable(String)` and `Toml#containsTableArray(String)` return true only if a key exists and is a primitive, table or array of tables, respectively. Compound keys can be used to check existence at any depth.
|
`Toml#contains(String)` verifies that the instance contains a key of any type (primitive, table or array of tables) of the given name. `Toml#containsPrimitive(String)`, `Toml#containsTable(String)` and `Toml#containsTableArray(String)` return true only if a key exists and is a primitive, table or array of tables, respectively. Compound keys can be used to check existence at any depth.
|
||||||
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
|
@ -246,7 +246,7 @@ public class Toml {
|
||||||
* @param key a key name, can be compound (eg. a.b.c)
|
* @param key a key name, can be compound (eg. a.b.c)
|
||||||
* @return true if key is present and is a primitive
|
* @return true if key is present and is a primitive
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(String key) {
|
public boolean containsPrimitive(String key) {
|
||||||
Object object = get(key);
|
Object object = get(key);
|
||||||
|
|
||||||
return object != null && !(object instanceof Map) && !(object instanceof List);
|
return object != null && !(object instanceof Map) && !(object instanceof List);
|
||||||
|
|
|
@ -29,15 +29,15 @@ public class ContainsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_contain_key() throws Exception {
|
public void should_contain_primitive() throws Exception {
|
||||||
Toml toml = new Toml().read("a = 1 \n [b] \n b1 = 1 \n [[c]] \n c1 = 1");
|
Toml toml = new Toml().read("a = 1 \n [b] \n b1 = 1 \n [[c]] \n c1 = 1");
|
||||||
|
|
||||||
assertTrue(toml.containsKey("a"));
|
assertTrue(toml.containsPrimitive("a"));
|
||||||
assertTrue(toml.containsKey("b.b1"));
|
assertTrue(toml.containsPrimitive("b.b1"));
|
||||||
assertTrue(toml.containsKey("c[0].c1"));
|
assertTrue(toml.containsPrimitive("c[0].c1"));
|
||||||
assertFalse(toml.containsKey("b"));
|
assertFalse(toml.containsPrimitive("b"));
|
||||||
assertFalse(toml.containsKey("c"));
|
assertFalse(toml.containsPrimitive("c"));
|
||||||
assertFalse(toml.containsKey("d"));
|
assertFalse(toml.containsPrimitive("d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -72,7 +72,7 @@ public class ContainsTest {
|
||||||
Toml toml = new Toml().read("a = \"1\"");
|
Toml toml = new Toml().read("a = \"1\"");
|
||||||
|
|
||||||
assertFalse(toml.contains("b.b1"));
|
assertFalse(toml.contains("b.b1"));
|
||||||
assertFalse(toml.containsKey("b.b1"));
|
assertFalse(toml.containsPrimitive("b.b1"));
|
||||||
assertFalse(toml.containsTable("b.b1"));
|
assertFalse(toml.containsTable("b.b1"));
|
||||||
assertFalse(toml.containsTableArray("b.b1"));
|
assertFalse(toml.containsTableArray("b.b1"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue