From b1436c557d56d9c82e59ac5059bb0ffb60549a9c Mon Sep 17 00:00:00 2001 From: "moandji.ezana" Date: Thu, 10 Dec 2015 12:23:08 -0400 Subject: [PATCH] Rename Toml#containsKey() to containsPrimitive --- CHANGELOG.md | 3 ++- README.md | 4 ++-- src/main/java/com/moandjiezana/toml/Toml.java | 2 +- .../java/com/moandjiezana/toml/ContainsTest.java | 16 ++++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3898842..b66fb1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ ### 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 * 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)__) ### Added @@ -15,6 +15,7 @@ * Support for underscores in numbers (the feature branch had accidentally not been merged into 0.4.0! :( ) * Set 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)__) +* Toml#contains(String) and Toml#containsXXX(String) methods to check for existence of keys ## 0.4.0 / 2015-02-16 diff --git a/README.md b/README.md index 4254d91..9473846 100644 --- a/README.md +++ b/README.md @@ -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. -[![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). @@ -221,7 +221,7 @@ Toml toml = new Toml().parse("a = 1"); Map 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 diff --git a/src/main/java/com/moandjiezana/toml/Toml.java b/src/main/java/com/moandjiezana/toml/Toml.java index abd8295..27a66d3 100644 --- a/src/main/java/com/moandjiezana/toml/Toml.java +++ b/src/main/java/com/moandjiezana/toml/Toml.java @@ -246,7 +246,7 @@ public class Toml { * @param key a key name, can be compound (eg. a.b.c) * @return true if key is present and is a primitive */ - public boolean containsKey(String key) { + public boolean containsPrimitive(String key) { Object object = get(key); return object != null && !(object instanceof Map) && !(object instanceof List); diff --git a/src/test/java/com/moandjiezana/toml/ContainsTest.java b/src/test/java/com/moandjiezana/toml/ContainsTest.java index 910b240..e3e5f35 100644 --- a/src/test/java/com/moandjiezana/toml/ContainsTest.java +++ b/src/test/java/com/moandjiezana/toml/ContainsTest.java @@ -29,15 +29,15 @@ public class ContainsTest { } @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"); - assertTrue(toml.containsKey("a")); - assertTrue(toml.containsKey("b.b1")); - assertTrue(toml.containsKey("c[0].c1")); - assertFalse(toml.containsKey("b")); - assertFalse(toml.containsKey("c")); - assertFalse(toml.containsKey("d")); + assertTrue(toml.containsPrimitive("a")); + assertTrue(toml.containsPrimitive("b.b1")); + assertTrue(toml.containsPrimitive("c[0].c1")); + assertFalse(toml.containsPrimitive("b")); + assertFalse(toml.containsPrimitive("c")); + assertFalse(toml.containsPrimitive("d")); } @Test @@ -72,7 +72,7 @@ public class ContainsTest { Toml toml = new Toml().read("a = \"1\""); assertFalse(toml.contains("b.b1")); - assertFalse(toml.containsKey("b.b1")); + assertFalse(toml.containsPrimitive("b.b1")); assertFalse(toml.containsTable("b.b1")); assertFalse(toml.containsTableArray("b.b1")); }