Skip to content

Commit 38aa6b3

Browse files
Update README.md
1 parent d19084d commit 38aa6b3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.thiagolvlsantos/json-predicate/badge.svg)](https://repo1.maven.org/maven2/io/github/thiagolvlsantos/json-predicate/)
99
[![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
1010

11-
12-
Predicate builder over a JSON specification. Specify you query in a JSON format and check it against a given object.
11+
Specify a predicate in a JSON format and check it against a given object.
1312

1413
## Usage
1514

@@ -25,9 +24,9 @@ Include latest version [![Maven Central](https://maven-badges.herokuapp.com/mave
2524

2625
## Predicates
2726

28-
The objective of this API is to create a `Predicate<Object>` based on a JSON specification of attributes and logical operations.
27+
The objective of this library is to create a `Predicate<Object>` based on a JSON specification which includes different types of predicates. The general idea is that these JSON predicates can be build using a GUI and be used in `filter` operations.
2928

30-
An example of a JSON predicate:
29+
An example of a JSON predicate filtering objects (or maps) whose field/key called 'name' contains the String 'project':
3130
```json
3231
{
3332
"name": {
@@ -36,19 +35,21 @@ An example of a JSON predicate:
3635
}
3736
```
3837

39-
Suppose there is a `List<Project>` where each project has a name, the following code will filter only those with `project` in its attribute name.
38+
Suppose there is a `List<Project>` where each project has a `String:name` attribute, the following code will filter only those with `project` in its attribute 'name'.
4039

4140
```java
41+
String filter = "{\"name\":{\"$contains\": \"project\"}}";
4242
IPredicateFactory factory = new PredicateFactoryJson();
43-
Predicate<Object> p = factory.read("{\"name\":{\"$contains\": \"project\"}}");
44-
List<Project> projects = ...//load list
43+
Predicate<Object> p = factory.read(filter);
44+
List<Project> projects = ...// loaded list from somewhere
4545
return projects.stream().filter(p).collect(Collectors.toList());
4646

4747
```
48+
In this example, if we provide the filter value using a GUI the underlying Java code remains unchanged.
4849

4950
## Predefined constructors
5051

51-
The set of build-in operators provided.
52+
Bellow a list of the built-in provided predicates, you can register you own predicate. Checkout the interface [`IPredicateManager`](https://github.com/thiagolvlsantos/json-predicate/blob/master/src/main/java/io/github/thiagolvlsantos/json/predicate/impl/PredicateManagerDefault.java) implementation.
5253

5354
### Logical operators
5455

@@ -74,7 +75,7 @@ The set of build-in operators provided.
7475
|$contains or $c | ``` {"name": {"$contains": "proj"} }```|
7576
|$ncontains or $nc | ``` {"name": {"$ncontains": "A"} }```|
7677
|$match or $m | ``` {"name": {"$match": "\d{8}"} }```|
77-
|$nmatch or $nm | ``` {"name": {"$nm": "\d{8}"} }```|
78+
|$nmatch or $nm | ``` {"name": {"$nmatch": "\d{8}"} }```|
7879

7980
## Build
8081

0 commit comments

Comments
 (0)